To my mind, a controller shouldn't need to know about the ugly
semantics of Javascript dependencies etc - it's entirely presentation
related, is irrelevant to other output types (xml, csv), etc...

And on a practical note, we have client-side guys in the team, who
don't really edit controllers etc.

I'm entirely happy with the general mechanism we're using at the
moment, I just want to make it a bit more seamless, i.e not
referencing viewVars in both the view and layout! Anyone advise on how
I'd wrap this up in method calls, where they would live, etc?


On Apr 8, 2:35 pm, jsundquist <[email protected]> wrote:
> Why not pass something from the controller to the layout and use a
> beforeRender?
>
> On Apr 8, 8:12 am, the_woodsman <[email protected]> wrote:
>
> > Exactly - the layout renders an analytics element, but it can pass it
> > a variable that was set in the actual view.
>
> > On Apr 8, 1:40 pm, John Andersen <[email protected]> wrote:
>
> > > Thanks for trying :)
>
> > > Do I understand correctly, that you are invoking/calling/whatever an
> > > element (Google Analytics) from the layout?
> > >    John
>
> > > On Apr 8, 2:27 pm, the_woodsman <[email protected]> wrote:
>
> > > > John, let me give it another go!
>
> > > > Googl analytics is still my best example.
>
> > > > I want every single page to have the basic analytics snippet.
> > > > I really don't want to have this in every single view- it'd be a big
> > > > job to go through all the existing views and add the call to render
> > > > the element (not very DRY), it makes my views more cluttered, and it
> > > > introduces the risk that pages are deployed without the snippet,
> > > > placing the burden on the developers to know about these snippets that
> > > > have to be placed in every view they create!
>
> > > > However, some pages need to completely override the default version in
> > > > the layout.
> > > > For example, analytics doesn't auto track 40x/50x HTTP responses, so I
> > > > want to change the analytics code for specific views.
>
> > > > So right now, my layout renders the analytics element, passing it a
> > > > variable form viewVars if necessary.
>
> > > > Then, my error page for 404s etc sets this variable to a custom value
> > > > ("error-404") so we can track how often our users hit error pages.
>
> > > > This technique is DRY (no unnecessary repetition of the same snippet),
> > > > employs convention over config (the convention is analytics is handled
> > > > in the layout, unless you're dealing with a special case), and there's
> > > > no risk of analytics not being included on a page.
>
> > > > None of the suggestions so far seem as elegant as this...?
>
> > > [snip]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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