Yii Framework Forum: Creating Common Layout - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Creating Common Layout Rate Topic: ***** 1 Votes

#1 User is offline   awebdeveloper 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 29-September 12

Posted 20 January 2013 - 01:22 PM

Here is a simplified html of my template

<div class="left">
    //some static content
</div>
<div class="right">
     //main content
</div>


For all ajax request i just want to load the content inside "right" but for all others it's the whole thing. The left content is same in most cases but changes in a few cases. So Is there a way i can override a block in the layout without using a variable to hold html something using BeginContent.

To make myself clear
  • For ajax requests i only render the view with ajax layout
  • For non ajax requests i render main template with view
  • For a few non ajax requests i render main template with view but i want a few changes in the main template content.



PS: I am aware of "renderPartial" and request->isAjaxRequest. My concern is the conetnt part
0

#2 User is offline   sifa786 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 12-February 13

Posted 13 February 2013 - 05:00 PM

View Postawebdeveloper, on 20 January 2013 - 01:22 PM, said:

Here is a simplified html of my template

<div class="left">
    //some static content
</div>
<div class="right">
     //main content
</div>


For all ajax request i just want to load the content inside "right" but for all others it's the whole thing. The left content is same in most cases but changes in a few cases. So Is there a way i can override a block in the layout without using a variable to hold html something using BeginContent.

To make myself clear
  • For ajax requests i only render the view with ajax layout
  • For non ajax requests i render main template with view
  • For a few non ajax requests i render main template with view but i want a few changes in the main template content.



PS: I am aware of "renderPartial" and request->isAjaxRequest. My concern is the conetnt part


Hi, let me try to give some response ...

You can set up multiple layouts in Yii ... by default in the protected/views/layouts/ folder you will find column1.php and column2.php. In your controller you can change the layout that is being used as follows:

  public $layout='//layouts/layoutxxx';


where layoutxxx is a layout you created

So, if you want to have 2 columns for example and have the right column load via ajax you could try something as follows (in layoutxxx.php):

<?php $this->beginContent('application.views.layouts.main'); ?>
<div class="span-5 last">
    <div id="sidebar">
        <?php $this->renderPartial('/admin/sidebar');?>
    </div><!-- sidebar -->
</div>
<div class="span-19">
	<div id="content">
		<!--?php echo $content; ?-->
        <?php
          $data = array();
          $data["content"] = $content;
          $this->renderPartial('/layouts/column1', $data); ?>

    </div><!-- content -->
</div>
<?php $this->endContent(); ?>

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users