We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How do I store a value in a variable for later use?

How Do I?

adlix's avatar
adlix
14 posts
about 2 months ago
adlix's avatar adlix

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

       
JCOGS Design's avatar
JCOGS Design
142 posts
about 2 months ago
JCOGS Design's avatar JCOGS Design

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 🐾

       
Zignature's avatar
Zignature
28 posts
one month ago
Zignature's avatar Zignature

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+

       
adlix's avatar
adlix
14 posts
one month ago
adlix's avatar adlix

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!

👍 1
       
adlix's avatar
adlix
14 posts
one month ago
adlix's avatar adlix

Hi JCOGS Design, I will try this first. I already use {layout} for definition of the different layout features. Perhaps is using it for snippets an enhancement for me. Thank you very much!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.