Keeps looking a little complicated to me, but it doesnt matter, we all
have different ways of solving problems... Here you have an useful
link for your purpose... 
http://cakebaker.42dh.com/2007/04/28/define-your-own-for_layout-variables/

Peace.

On Nov 1, 8:58 am, Marcin Jaworski <[EMAIL PROTECTED]> wrote:
> I don't think that elements are a good solution to this problem. What
> if I want to have a dynamically changing side column on my page, that
> is dependent on the main content (controller, action or even
> parameters)? Using elements, I would need to create element that would
> also get the data to display depending on the Cake's path or include
> some logic in layout so it would display different contents in side
> column. This would be a lot of work and it would require to add new
> code to element/layout when adding new controllers.
>
> Of course I could do the layout without the columns and just render
> columns' divs in each view, but I think that is not the Cake's way
> either (page's layout should be defined as a whole in layout files).
>
> Using predefined "containers" (in this case "$*_for_layout" variables)
> the layout itself is independent from the controllers/views. All you
> need to know is the name of those additional contents in layout file
> and just render it in your view. You can add new controllers and views
> without adding the support for them in layout or some kind of element.
> You can for example place links list of the months/years in /news/
> index and list of this month news when in /news/show/someid. But you
> can without the problem display for example a list of similar topics
> when displaying some forum post etc. The layout won't need to know
> what you need to display.
>
> It would be also great having nested layouts (as I mentioned in my
> first reply):
>
> --- mainlayout.ctp ---
>
> <html>
> <head><!-- html headers here --></head>
> <body>
> <div id="container">
> <div id="header"><!-- page header --></div>
> <?= $content_for_layout ?>
> <div id="footer"><!-- page footer --></div>
> </div>
> </body>
> </html>
>
> ------
>
> --- onecolumnlayout.ctp ---
>
> <? $this->layout = 'mainlayout.ctp'; ?>
>
> <div id="singlecolumn">
> <?= $content_for_layout ?>
> </div>
>
> ------
>
> --- twocolumnslayout.ctp ---
>
> <? $this->layout = 'mainlayout.ctp'; ?>
>
> <div id="maincolumn">
> <?= $content_for_layout ?>
> </div>
>
> <div id="sidecolumn">
> <?= $sidecontent_for_layout ?>
> </div>
>
> ------
>
> Then in the controller, one could just select the layout from
> onecolumnlayout and twocolumnslayout depending on the needs and those
> layouts with rendered contents could be rendered as
> $content_for_layout in the mainlayout. This way we have only one place
> where we define headers, footers and the html stuff, and we follow the
> Cake's way of doing things defining columns in layouts and not in
> every view. And probably it would save a lot of work to many people
> out there :).
>
> On 1 Lis, 00:34, mbavio <[EMAIL PROTECTED]> wrote:
>
> > On Oct 31, 10:37 am, Marcin Jaworski <[EMAIL PROTECTED]> wrote:
>
> > > Hi.
>
> > > This is me again :).
>
> > > I did the search and I found a possible solution using ob_start() and
> > > ob_get_clean() functions. Like in my previous ideas it is something
> > > like content placeholders.
>
> > > view:
>
> > > <div>This is some view. This is it's main content</div>
> > > <? ob_start(); ?>
> > > this content won't be rendered as $content_for_layout
> > > <? $GLOBALS['namedContents']['somename'] = ob_get_clean(); ?>
>
> > > then in layout:
>
> > > <div id="leftcol"><?= $content_for_layout ?></div>
> > > <div id="rightcol">
> > > <? if (isset($GLOBALS['namedContents']['somename'])) { echo
> > > $GLOBALS['namedContents']['somename']; } else { ?>
> > > Here goes the default content for this placeholder
> > > <? } ?>
> > > </div>
>
> > > When no default content is required then just simply <?=
> > > $GLOBALS['namedContents']['somename'] ?> where it is needed.
>
> > > However I haven't tested this yet. It's only an idea. Maybe it could
> > > be wrapped in a Helper?
>
> > > This should not break existing buffering using ob_start() because as I
> > > have read on in the php manual, buffers are stackable (it is possible
> > > to call ob_start inside a buffer and this will create a new buffer on
> > > top of that first).
>
> > Wow! Seems very complex. Why no to try the simple methodology of
> > CakePHP and use elements (http://bakery.cakephp.org/articles/view/
> > creating-reusable-elements-with-requestaction) to create reusable
> > parts of code that you can put everywhere...
> > An advice... Always try to solve first in the Cake way, i´m sure
> > you`re gonna save a lot of time.
>
> > Have a nice day.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to