I’m using a single ‘layout’ template to wrap each of my ‘content’ templates (ie. each content template starts with {layout="layouts/_layout_general"} ). In almost every case it is working out fine but in just three cases – all related to the news section of the site – the layout loses some of its code.
Some of the layout template involves the site navigation, and certain items in that menu have sub-menus. These sub menus are built dynamically from channel:entry data. It’s working fine, except that when the layout is called via any one of three content templates – news/month, news/year, or news/article – the submenus in the layout disappear from the markup entirely. The news/index template also calls the layout, and in that instance the submenus are fully present and correct. I’ve even tried commenting out almost all the code in the news/year template to try and isolate the problem, but it made no difference. So maybe it’s not something in the content template after all. But what else could it be?
Note that the missing markup isn’t just hidden with css; it appears to be entirely missing from the source code. In each case the missing content is stuff that would be generated from within a channel:entries tag pair. But the C:E syntax is okay, because it works fine when the layout is called by other templates.
The only layout variables (parameter or dynamic) that I am using are used to set SEO meta data in the page head, so I’m pretty sure that’s not the culprit. Happy to be proved wrong, though.
So: without getting into the nitty gritty of the template code (yet), can anyone think of a reason why the same layout might render differently depending on which template calls it, assuming that the differences are not down to layout variables? Because it’s got me baffled.
Thanks.
There’d be quite a lot of code, so I thought I’d ask initially without pushing that much horror in front of people’s eyes. But yes, of course. I guess there’s not much point in posting a truncated version of the code, since we don’t know where the problem lies. I will add that I’ve tried commenting out EVERYTHING in the ‘content’ template except the {layout="xxx"} tag, (including removing all layout variable parameters) and the problem persists.
If the issue was a dynamic=no then I’d expect the problem to manifest regardless of which template was calling the layout. But, as I type this, I realise that I haven’t actually tried that step (for exactly the reason stated), so I’ll try it now.
Mike, that was it! Thank you. And how much do I hate being caught out by dynamic=”no”? But I’m still confused as to why the other content templates all rendered fine. Except… it occurs to me now (now that the problem is pinned down) that the ‘problem’ templates were the only ones that weren’t ‘index’ templates of their respective template groups. So: does dynamic=”no” only come into play when a template creates a segment above 1st (ie. isn’t index)?
Still… dynamic=”no”. What a horrible, rookie error. The shame.
Dynamic being left on means the channel:entries tag is looking to the URL for help on what entries to pull. Index templates have shorter URLs which provide less direction, so the channel:entries tag just pulls everything.
With non-index templates providing more URL direction the channel:entries tag tries to find a match, but fails so returns nothing.
Basic rule of thumb is to set dynamic to no on any templates that have to run anywhere - to break that URL to channel:entries results connection.
Thanks for the clarification on that, Mike. Sadly, for me, your answer arrived just moments after I posted the same problem to expressionengine.stackexchange.com (should’ve been more patient, but I’m up against a deadline and got panicky), so now I get to be humiliated in two forums. My own damn fault. 😉
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.