Hi, it seems to be a default case, but I haven’t found a solution yet.
I have to display a master entry. This entry defines e.g. an ID for a category. The entries for this category should be shown after the master entry as list.
I don’t want to use PHP for this. Is there something like a template variable?
{exp:channel:entries channel="master"}
{layout:set name="catid"}{sdg_categoryid}{/layout:set}
{/exp:channel:entries}
{!-- doesn't work --}
{layout:catid}{value}{/layout:catid}
{layout:catid}
{exp:channel:entries channel="details"
limit="5"
category_group="20"
dynamic="off" orderby="date"
sort=“asc”
category_id="{catid}"}
{/exp:channel:entries}
Thanks for your answer.
Matthias
Hi Matthias.
Your code should work - probably what you are missing is the need to split your code between two templates. Layout variables are a side-effect of Template Layouts and only operate when you are using the Template Layout approach.
The reason for this is that Layout variables are only instantiated when the processing of the template concerned is completed - but once done the values remain available through out the rest of the processing of however many templates you have in your layout stack.
So all you need to do (probably - your code example is possibly not so clear) is split your code fragment across two templates.
So for example, if your first template is called “template.html” and the second is called “_template.html” and both are in template group “group”, you might end up with these two bits of code:
{layout="group/_template} {!-- this redirects from the first template to the second --}
{exp:channel:entries channel="master"}
{layout:set name="catid"}{sdg_categoryid}{/layout:set}
{/exp:channel:entries}
and in _template.html
{layout:catid}{value}{/layout:catid}
{layout:catid}
{exp:channel:entries channel="details"
limit="5"
category_group="20"
dynamic="off" orderby="date"
sort=“asc”
category_id="{catid}"}
{/exp:channel:entries}
When you get the hang of the approach, Template Layouts are really useful and allow you to do all manner of cute things within EE templates. So worth finding out more about. HTH 🐾
Try the Stash add-on if Layout Variables don’t work for you.
https://github.com/croxton/Stash
Compatible with EE 3.0 - 7.0+
Thanks. This would have been my next step - developing such an extension. Great. That it’s already there. I’m really wondering if this shouldn’t be a standard feature. So often I have to make a workaround for similar situations. Is it my wrong thinking?
Thanks a lot!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.