tags:

views:

104

answers:

2

I have a fresh CakePHP 1.3 install and it currently has one layout. I am about to add a few more but I don't want to have to keep coping and pasting the Header and footer in to each layout.

At first I thought that I could do this with an Elements, but it does not seem to render the Configure::read('var_name'); chunks while in an element.

My other thought was to create a common layout and use lots of variables to add and remove sections from the screen depending on what type of user they are... but this would be troublesome to say the lest.

My question is: Is a way to include a header/footer section in to a layout while getting the Configure::read() function to output text?

+3  A: 

I still think that elements are the right way to go for this (shared view snippets, FTW). I have to admit that I'm a little surprised that elements can't read from the Configure class, but I'll concede that I haven't tried it. If that really won't work, then try passing the values directly to the element:

<?php echo $this->element( 'partial_name', array( 'var_name', Configure::read( 'var_name' ); ?>

In the element, you should then be able to access the variable simply as $var_name. For more on passing variables to elements, take a look at the [Passing Variables into an Element](Passing Variables into an Element) section of the element documentation.

Hope that helps.

Rob Wilkerson
+1 The `Configure` class is globally available throughout Cake, it's not *unincluded* in elements (it can't be) or anything like that. The OP just has some problem in his code.
deceze
A: 

Create element with new header suppose new_header.ctp. Then put element('new_header')?> in your preferred position layout

Abdul Gaffar
Please see @Rob Wilkerson response. that does work but you can not access the variables from the configure class.
Steven smethurst