Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added view option to render a view with Yii inside tab content #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
declare(strict_types=1);

namespace yii\bootstrap5;

use Yii;
use Exception;
use Throwable;
use yii\base\InvalidConfigException;
Expand Down Expand Up @@ -75,6 +75,7 @@ class Tabs extends Widget
* - headerOptions: array, optional, the HTML attributes of the tab header.
* - linkOptions: array, optional, the HTML attributes of the tab header link tags.
* - content: string, optional, the content (HTML) of the tab pane.
* - view: array, optional, the view that should be rendered with Yii::$app->controller->view->render
* - url: string, optional, an external URL. When this is specified, clicking on this tab will bring
* the browser to this URL. This option is available since version 2.0.4.
* - options: array, optional, the HTML attributes of the tab pane container.
Expand Down Expand Up @@ -232,7 +233,12 @@ protected function prepareItems(array &$items, string $prefix = '')

if ($this->renderTabContent) {
$tag = ArrayHelper::remove($options, 'tag', 'div');
$this->panes[] = Html::tag($tag, $item['content'] ?? '', $options);
$view = ArrayHelper::getValue($item, 'view');
$content = ArrayHelper::getValue($item, 'content', '');
if (!$content && $view) {
$content = Yii::$app->controller->renderPartial($view[0], ArrayHelper::getValue($view, 1, []));
}
$this->panes[] = Html::tag($tag, $content, $options);
}
}
}
Expand Down
Loading