-1

I have a general layout. (default) But for users pages, I should add a panel to each page.

I tried $this->renderLayout('panel_code', 'default');, but didn't work; and printed default layout view view content! with no panel_code!

Where's my mistake?

mrdaliri
  • 7,148
  • 22
  • 73
  • 107

1 Answers1

1

You should make elements in View/Elements folder with .ctp extension.

This link would help you to make clean separation of your view files with the related/repeated code.

An element is basically a mini-view that can be included in other views, in layouts, and even within other elements. Elements can be used to make a view more readable, placing the rendering of repeating elements in its own file. They can also help you re-use content fragments in your application.

Elements live in the /app/View/Elements/ folder, and have the .ctp filename extension. They are output using the element method of the view:

<?php echo $this->element('helpbox'); //without extension ?>

You can pass variables from your view to the element.

In your view:

 <?php echo $this->Element('reviews/view-goal', array('history' => $history));

In view-goal.ctp element you can directly access $history variable.

Arun Jain
  • 5,476
  • 2
  • 31
  • 52