Multiple layouts: how does it work?
Rate Topic:

I've been looking at the default code generated by yiic. It creates a 1-column and a 2-column layout.

The default column2.php uses beginContent() and endContent(). Inbetween these two functions there is some code that is to replace a part of the code in main.php. My attempts to alter these files have not been very successful. I can't figure out how it determines what to replace - and what not to replace.

How does this work? Are there certain div classes or id's it looks for? it replaces some parts of the code in the container div, but others remain... I'm confused

This is as much a question as an answer, the layouts are a little confusing. Can there only be one $content sent to the page?

I end up doing a lot of data access from the views, and I would rather be doing it from the controller. I'm not sure I am being clear here.

When you define $this->layout that seems to be the end of the line so if $this->layout is column2 because the layout view column2.php starts with <?php $this->beginContent('application.views.layouts.main'); ?> Yii knows to look for that layout, at least that's how I understand what's going on.

This is as much a question as an answer, the layouts are a little confusing. Can there only be one $content sent to the page?

I end up doing a lot of data access from the views, and I would rather be doing it from the controller. I'm not sure I am being clear here.

When you define $this->layout that seems to be the end of the line so if $this->layout is column2 because the layout view column2.php starts with <?php $this->beginContent('application.views.layouts.main'); ?> Yii knows to look for that layout, at least that's how I understand what's going on.

I'm using a theme. This means my /protected/views is as empty as possible. It does not even contain a layouts folder. Everything is in /themes/themeName/views, including the layouts folder. I've also built a module, and it looks for its layout in /protected/modules/moduleName/views/layouts. I don't want that because it doesn't need its own layout and I want to reuse code as much as possible.

How do I make it look for the layout in the views of the theme folder in stead of within the module views?

The least code duplication I've managed to achieve so far is by creating the column1.php (and others) file and refer it to the themed main.php like this: