Theme, template, views and partial views in Yii application

Hi, is there a tutorial or something similar on how to create a complex layout with Yii?

For complex layout I mean a page divided (for example) in header, sidebar, content and footer sections.

And a subdivision for each one of them: “header” with topHeader and logoHeader, “sidebar” and “content” with blocks dinamically populated… what’s best strategy to create a layout like that?

In views/layout/main.php there is a $content var that renders output. How to create a $header or $sidebar ones?

TIA

Danilo

At this time you cannot push data to the layout. However, you can use the pull method in which you define public properties in your controller, and read it in your layout ($this always refers to the current controller in view files).

I hope this helped.

i don’t understand… maybe with an example it can be easier.

if I want to create block1 with latest 5 news and block2 with a list of friend sites in the "sidebar" DIV of my layout… is it possible to do that with Yii?

is it possible to make them “indipendent” from main controller? (I ì’ve understood that it is not possible)

is it possible to do same thing with $content?

tia

danilo

Have you seen this cookboook article? Maybe it gives some ideas:

http://www.yiiframework.com/doc/cookbook/28/

Really interesting, thanks :slight_smile:

It is also possible to define clips in your view file and access it in your layout

view file


$this->beginClip('sidebar');

This is my sidebar content

$this->endClip('sidebar');

layout file


if (isset($this->clips["sidebar"])) {

    echo $this->clips["sidebar"];

} else {

    echo "This is my default sidebar content"

}

I do this, but set it up in the BaseController:




function clip($id, $content=null, $properties=array()) {

  $this->beginClip($id, $properties);

  print $content;

  $this->endClip($id);

}



This way I can avoid all the conditionals.




# layout

$this->clip('sidebar', $content);

# view

echo $this->clips["sidebar"];