Templates 如何在yii2中仅在索引页上显示滑块
我在Templates 如何在yii2中仅在索引页上显示滑块,templates,render,yii2-basic-app,Templates,Render,Yii2 Basic App,我在\u carousel.php中的yii2中有一个图像滑块。当调用actionIndex时,我想在main.php中呈现这个部分表单。我所做的是将呈现的html代码保存在一个变量中并发送到索引,但在main.php中无法识别。在actionIndex中,如何缓存它并在main.php中显示: $_carousel = $this->renderPartial('_carousel'); return $this->render('index', [ 'ca
\u carousel.php
中的yii2中有一个图像滑块。当调用actionIndex
时,我想在main.php
中呈现这个部分表单。我所做的是将呈现的html代码保存在一个变量中并发送到索引,但在main.php中无法识别。在actionIndex中,如何缓存它并在main.php中显示:
$_carousel = $this->renderPartial('_carousel');
return $this->render('index', [
'carousel' => $_carousel
]);
类似于yii 1.4中的以下代码:
$this->beginClip('bannerSlideshow');
echo $this->renderPartial('//layouts/banner');
$this->endClip();
main.php是您的布局吗?当您调用actionIndex()(这是您在控制器中的操作,对吗?)并将“旋转木马”分配给控制器的索引视图时,您实际上得到了所需的内容。您只能将“转盘”分配给索引站点上的视图 但是您知道哪个操作正在执行您的布局。 在布局main.php中
。。。
//$this->context->id//这是当前执行的控制器
//如果应用程序中有多个索引,请将其与controllerId组合。
如果($this->context->action->id=='index'){
echo$this->render(/{controller}/_carousel);//您在main.php中呈现的carousel。
//当您使用模块时,这应该是
echo$this->render(//{controller}/_carousel);
....
}
另请参见此答案对您有用吗?