Thanks Brian - but I don't understand how this addresses the issue...

Are you saying I can render the element twice, without bothering with
an if statement, and it will only get echo'd once?

And the real question - how do I get the value 'foo' into the layout
from the view!? $this->viewVars is how I'm doing it currently...

On Apr 7, 5:29 pm, brian <bally.z...@gmail.com> wrote:
> $this->element('google_analytics');
>
> $this->element(
>         'google_analytics',
>         array(
>                 'customSnippet' => 'foo'
>         )
> );
>
> google_analytics.ctp:
>
> if (isset($customSnippet))
> {
>
> }
>
> else
> {
>
> }
> On Tue, Apr 7, 2009 at 9:15 AM, the_woodsman <elwood.ca...@gmail.com> wrote:
>
> > Hmm - maybe I'm just being picky, but that doesn't sound right to me
> > either!
>
> > The layouts are obviously the same barring these overriden sections,
> > so the idea of duplicating entire layouts, inc nav etc, and maintaing
> > them seperately seems like a lot of work.
>
> > Add to that the cross combination issue - say if I have the analytics
> > snippet as described above, and also some call to JS of my own that
> > needs to be overridable.
>
> > Would I need a defautl layout, a custom-analytics layout, a custom-
> > myscript layout, a custom-analytics-and-custom-myscript layout, etc?!?
>
> > And finally, the idea that my controllers need logic for javascript
> > and analytics, which in my head is purely presentational, seems wrong
> > too.
>
> > My current setup is, in pseudo-code, is something like this:
>
> > == Default layout ==
>
> > if($this->viewVars['customSnippet'])
> > {
> >   $this->renderElement('my-snippet', $this->viewVars
> > ['customSnippet']);  // slightly customised version of the element
> > }
> > else
> > {
> >  $this->renderElement('my-snippet'); //generic version of the element
> > }
>
> > == Custom View ==
> > $this->viewVars['customSnippet']='snippet just for this particular
> > view';
>
> > This means the default element is rendered for all pages, unless
> > overridden in a particular view.
> > It took us a while to work this out, but it works quite well - it's
> > just I find the use of $this-<viewVars all over the place a bit
> > clunky.
>
> > As I said, maybe I'm just being a perfectionist :|
>
> > On Apr 7, 1:58 pm, John Andersen <j.andersen...@gmail.com> wrote:
> >> As far as I understand, CakePHP takes the presentation so that the
> >> Elements goes into the Views, which goes into the Layout.
> >> [example] Layout <- Views <- Element [/example]
>
> >> If you have a part in the Layout, that occasionally should contain
> >> something else, then maybe you could let the controller set another
> >> layout, where the part has been replaced by the occassionally
> >> presented part.
>
> >> How does this sound to you?
> >> Enjoy,
> >>    John
>
> >> On Apr 7, 3:48 pm, the_woodsman <elwood.ca...@gmail.com> wrote:
>
> >> > Thanks John -
>
> >> > But I see a few issues with that approach.
> >> > Let me give an example - google analytics occasionally needs to be
> >> > overridden on specific pages (i.e to register a custom page view,
> >> > rather than the one in the address bar).
>
> >> > It doesn't seem right to me that every single view needs to include
> >> > the google analytics snippet - passing custom info to the view as and
> >> > when we need seems a lot nicer than refactoring every single view in
> >> > the system, and ensuring that new developers to the project know of
> >> > all these mystical, business critical elements they have to place in
> >> > every new view they create....
>
> >> > On Apr 7, 1:35 pm, John Andersen <j.andersen...@gmail.com> wrote:
>
> >> > > I suggest taking the common part of the layout out from the layout and
> >> > > create it as an element, then invoke it from the view, passing the
> >> > > data to the element.
> >> > > Enjoy,
> >> > >    John
>
> >> > > On Apr 7, 3:03 pm, the_woodsman <elwood.ca...@gmail.com> wrote:
>
> >> > > > Hi fellow bakers,
>
> >> > > > I often need to pass presentation related data from the view to the
> >> > > > layout - for example, when the layout has somethign for every singel
> >> > > > page, that individual pages can customise / override.
>
> >> > > > So far, the best solution I've found is to set things in the view via
> >> > > > the viewVars array, which is accesible in the layout.
>
> >> > > > Does Cake provide a way to do this more elgantly? Is there a
> >> > > > View::passToLayout function?
> >> > > > If not, what would be the best practice for implementing such a 
> >> > > > thing?
>
> >> > > > 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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to