Coksnuss
(Schanz15)
October 7, 2011, 6:46pm
1
Hi,
I am trying to render a view within my layout but I dont get it working.
themes/classic/views/layouts/main.php
[PHP]
<?php echo $content; ?>
<!-- Some code -->
<div>
<?php $this->renderPartial(’_myViewFile’); ?>
</div>
<!-- Some code -->
[/PHP]
I expected that ‘_myViewFile’ is beeing searched within the directory ‘themes/classic/views’ - But the file is beeing searched within the view directory which is determined by the current active controller / module.
I now used $this->renderFile() and used the absolute path to the file - But it seems wrong. What do i miss?
read this http://www.yiiframework.com/doc/guide/1.1/en/topics.theming
You have also the // for the views, to go to the "base" of the views and start building the path from it
also you need to set the theme , for this you can use my theme picker, see in signature
Coksnuss
(Schanz15)
October 7, 2011, 7:30pm
3
I am through this… I still dont get the solution… The theme is set and working!
webmastak
(5704709)
January 10, 2013, 12:50pm
4
Coksnuss:
Hi,
I am trying to render a view within my layout but I dont get it working.
themes/classic/views/layouts/main.php
[PHP]
<?php echo $content; ?>
<!-- Some code -->
<div>
<?php $this->renderPartial(’_myViewFile’); ?>
</div>
<!-- Some code -->
[/PHP]
I expected that ‘_myViewFile’ is beeing searched within the directory ‘themes/classic/views’ - But the file is beeing searched within the view directory which is determined by the current active controller / module.
I now used $this->renderFile() and used the absolute path to the file - But it seems wrong. What do i miss?
My friend, it’s very simple. Use $this->renderPartial(’/layouts/_partial’);
louisgac
(Louisgac Development)
June 14, 2014, 10:31am
5
Also :
http://www.yiiframework.com/doc/api/1.1/CController#getViewFile-detail
Otherwise, this method will return the corresponding view file based on the following criteria:
absolute view within a module: the view name starts with a single slash ‘/’. In this case, the view will be searched for under the currently active module’s view path. If there is no active module, the view will be searched for under the application’s view path.
absolute view within the application: the view name starts with double slashes ‘//’. In this case, the view will be searched for under the application’s view path. This syntax has been available since version 1.1.3.
aliased view: the view name contains dots and refers to a path alias. The view file is determined by calling YiiBase::getPathOfAlias(). Note that aliased views cannot be themed because they can refer to a view file located at arbitrary places.
relative view: otherwise. Relative views will be searched for under the currently active controller’s view path.
So, it’s better to use double slashes :
$this->renderPartial('//layouts/_partial');