If it's the same header on every view, just call it in the layout. If, on the other hand, it's the same header in MOST views, use the chunks helper as above:
some_view.ctp: <?php $chunks->begin('header'); ?> This will end up in the header <?php $chunks->end(); ?> your_layout.ctp: <?php if (!empty($header_for_layout)) { // A header has been defined in the view, so show it echo $header_for_layout; } else { // No header has been defined; use the default one echo $this->element('default_header'); } ?> elements/default_header.ctp: This is the default header Easy, huh? hth grigri On Nov 13, 5:14 pm, i_Am_ToO_SeXy <[EMAIL PROTECTED]> wrote: > Uhm... another little problem... > > What about a default Header? (Same header on every view) > > How can i do? using AppController? > > On 13 Nov, 12:30, grigri <[EMAIL PROTECTED]> wrote: > > > Indeed, the beforeLayout() callback doesn't seem to work. > > > If works if you put it in afterRender() > > though:http://bin.cakephp.org/view/815089959 > > (tested this time) > > > (same usage) > > > hth > > grigri > > > On Nov 13, 10:13 am, i_Am_ToO_SeXy <[EMAIL PROTECTED]> wrote: > > > > Hi grigri > > > Thanks for the reply. > > > > I followed your suggestions but i can't get the code work. > > > > No errors but also no outputs :\ > > > > BTW i modified a little bit the layout code > > > > <body> > > > <div id="container"> > > > <div id="header"><?php if > > > (isset($header_for_layout)) { echo > > > $header_for_layout; } ?></div> > > > <div id="leftbar"><?php if > > > (isset($leftbar_for_layout)) { echo > > > $leftbar_for_layout; } ?></div> > > > <div id="rightbar"><?php if > > > (isset($rightbar_for_layout)) { echo > > > $rightbar_for_layout; } ?></div> > > > <div id="content"><?php if > > > (isset($content_for_layout)) { echo > > > $content_for_layout; } ?></div> > > > <div id="footer"><?php if > > > (isset($footer_for_layout)) { echo > > > $footer_for_layout; } ?></div> > > > </div> > > > </body> > > > > Sorry for my n00bness :( > > > > On 12 Nov, 17:55, grigri <[EMAIL PROTECTED]> wrote: > > > > > Off the top of my head, I'd suggest using a helper combined with > > > > output buffering, like this: > > > > > class ChunksHelper extends AppHelper { > > > > var $chunkId = null; > > > > var $append = false; > > > > var $buffer = array(); > > > > > function begin($chunkId, $append = false) { > > > > if (empty($this->chunkId)) { > > > > $this->chunkId = $chunkId; > > > > $this->append = $append; > > > > ob_start(); > > > > } > > > > } > > > > > function end() { > > > > if (!empty($this->chunkId)) { > > > > $contents = ob_get_clean(); > > > > if ($this->append) { > > > > if (isset($this->buffer[$this->chunkId])) { > > > > $this->buffer[$this->chunkId] .= $contents; > > > > } > > > > else { > > > > $this->buffer[$this->chunkId] = $contents; > > > > } > > > > } > > > > else { > > > > $this->buffer[$this->chunkId] = $contents; > > > > } > > > > $this->chunkId = false; > > > > } > > > > } > > > > > function beforeLayout() { > > > > $View =& ClassRegistry::getObject('View'); > > > > foreach($this->buffer as $key => $value) { > > > > $View->set($key . '_for_layout', $value); > > > > } > > > > } > > > > > } > > > > > Then in your view: > > > > > <?php $chunks->begin('rightbar'); ?> > > > > This will end up in the right bar > > > > <?php $chunks->end(); ?> > > > > > (The code might need a bit of modifying; I just wrote it quickly, but > > > > the idea is sound. You'll definitely want to add error-checking) > > > > > hth > > > > grigri > > > > > On Nov 12, 4:11 pm, i_Am_ToO_SeXy <[EMAIL PROTECTED]> wrote: > > > > > > Hello all. > > > > > First time posting here. > > > > > > I have a 3-column layout where the 3rd column is intended to be a > > > > > menu. > > > > > here's the code > > > > > > <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> > > > > > <head> > > > > > <?php > > > > > echo $scripts_for_layout; > > > > > echo $html->css("green", "stylesheet"); > > > > > ?> > > > > > <title>Erny - <?php echo $title_for_layout; ?></title> > > > > > </head> > > > > > <body> > > > > > <div id="container"> > > > > > <div id="header"><?php echo > > > > > $header_for_layout; ?></div> > > > > > <div id="leftbar"><?php echo > > > > > $leftbar_for_layout; ?></div> > > > > > <div id="rightbar"><?php echo > > > > > $rightbar_for_layout; ?></div> > > > > > <div id="content"><?php echo > > > > > $content_for_layout; ?></div> > > > > > <div id="footer"><?php echo > > > > > $footer_for_layout; ?></div> > > > > > </div> > > > > > </body> > > > > > </html> > > > > > > The right menu should change his html code based on the current view. > > > > > I googled a lot but the only way i found is to use a Helper inside the > > > > > controller... that's not very MVC-ish... > > > > > So... is there any better way? :) > > > > > > Thanks in advance. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---