$content inserting some extra divs programatically

As per YII documentation, Iam using variable "$content" in layouts. I came to know that it is inserting two extra divs "container" and "content" before actual data. Actually it is boxing data with these two divs.

Can some one guide me how to remove these two divs.

Thanks in advance

It doesn’t insert anything. Check layouts “protected/views/layouts/column1.php” and “protected/views/layouts/column2.php”.

Did the answer from andy_s work for you? I am having the same problem. Here is the source view of the view showing the extra divs:

<body>

&lt;div id=&quot;X&quot;&gt;


	&lt;div id=&quot;logo&quot;&gt;&lt;img id=&quot;logo&quot; src=&quot;&quot; alt=&quot;&quot; height=&quot;50px&quot; width=&quot;100px&quot;&gt;&lt;/img&gt;&lt;/div&gt;





	&lt;div class=&quot;container&quot;&gt;


&lt;div id=&quot;content&quot;&gt;

<div id="input">aaaaa</div><!–input–> </div><!-- content -->

</div>

	&lt;div id=&quot;footer&quot;&gt;&amp;nbsp;&lt;/div&gt;&#60;&#33;--footer--&#62;

</div><!–X-->

</body>

The div class="container"> and <div id="content"> were added. Neither the layout or the index.php file contained either of these extra divs.

Any thoughts?

When you render a view, the content of the view will be populated into a variable named $content which will then be passed to the layout file.

The layout file of a controller is ‘//layouts/column1’ if you haven’t changed the default.

So, check your ‘protected/views/layouts/column1.php’. It must be like this …




<?php $this->beginContent('//layouts/main'); ?>

<div class="container">

    <div id="content">

        <?php echo $content; ?>

    </div><!-- content -->

</div>

<?php $this->endContent(); ?>



// As you may notice, the content of the ‘columm1’ layout (which contains the content of the view) will also be passed to another layout file that is ‘main.php’.

If you don’t like the “extra” 2 divs, you may delete them.




<?php $this->beginContent('//layouts/main'); ?>

<?php echo $content; ?>

<?php $this->endContent(); ?>



But in that case you should provide an appropriate set of CSS files on your own, or you will get somewhat broken outputs on the screen, because the default CSS files of Yii framework refer to the "container" and "content" divs to define the screen layouts.

Thanks for your reply. I have studied it but I am still confused about the default layout. In the demo application I find this code in the SiteController.php:

/**


 * This is the default 'index' action that is invoked


 * when an action is not explicitly requested by users.


 */


public function actionIndex()


{


	// renders the view file 'protected/views/site/index.php'


	// using the default layout 'protected/views/layouts/main.php'


	&#036;this-&gt;render('index');


}

This implies that the default layout is main.php and not column1.php. I have, perhaps erroneously, edited the main.php to suit my needs and edited index.php to contain the desired content.

It is almost as though my application is using my modified main.php layout, rendering column.php layout inside main.php layout and inserting my index.php into the column1.php layout.

I search through the "Definative Guide to Yii" and found this statement in the layout section "By default, the view script protected/views/layouts/main.php is used as the layout.".

Apparently I am missing something.

Check Controller.php in components folder (i.e. your controllers will most likely extend from it).

Thank you.

There should be a difference between the layout structures of the demo application (which you’ve been reading) and the skeleton application created by yiic.

demo : view - main

skeleton : view - column1 - main

And there’s no harm in abandoning the layout structure of the skeleton. You don’t have to stick to the “view - (column1|column2) - main” scheme, and it’s okay to do it as you like, only if you are willing to modify the default CSS files or write them on your own.