6

I'm trying to use Stash 2.1.0 on an ExpressionEngine 2.5.3 site but, strangely, I cannot get even the Simple Example found on Devot:ee to work, even on what is an otherwise blank template.

{exp:channel:entries channel="work" limit="1" dynamic="no" disable="member_data|pagination|categories"}
Expected: {title} /
{exp:stash:set name="title"}{title}{/exp:stash:set}
{/exp:channel:entries}

{!--Now you can access like this in an embedded template or later in the parse order of the same template:--}
Result: {exp:stash:get name="title"}

For troubleshooting purpose, in my {exp:channel:entries} pair I am displaying the title of that entry but the {exp:stash:set} is apparently not working.

I have confirmed the module is installed. The Github page doesn't list specific requirements but I would assume that if I can run EE 2.5.3, then whatever is on the server in terms of PHP or whatnot should support Stash as well.

Any thoughts on how to troubleshoot this? Or is there some incantation I need to utter before Stash will work?

  • 1
    I highly recommend using the dev branch. v2.1.0 is rather old and missing a ton of the new features. 2.3.x is definitely stable enough for production. – Justin Kimbrell Dec 21 '12 at 15:52
7

More often than not I usually put Stash on the outside of a channel entries tag, which should get around your issue, eg:

{exp:stash:set parse_tags="yes"}
    {exp:channel:entries limit="1"}
       {stash:title}{title}{/stash:title}
    {/exp:channel:entries}
{/exp:stash:set}

{!--Now you can access like this in an embedded template or later in the parse order of the same template:--}
Result: {exp:stash:get name="title"}
| improve this answer | |
  • 2
    Another benefit to this approach: You can use save="yes" to cache the {exp:stash:set} tag so that subsequent calls bypass the {exp:channel:entries} tag altogether. This eliminates a ton of queries. – Dom Stubbs Dec 21 '12 at 16:22
6

The important part is "later in the parse order". Are you trying to use the get within the same template as the set? If you are, you may have to add a priority parameter. I've had the best luck separating them entirely - by using a single embed as a wrapper template. So in my "about" template, I have nothing but channel logic and my "set" to stash the elements i need as variables, and an embed called "inside". Then in my "inside" template I use get to retrieve the stashed variables. If I continue to stash things with the same nomenclature (such as "page_body" for example), I'm able to use one "inside" template for virtually any page, since stash stores the variables on the basis of the URL that called for them.

| improve this answer | |
  • Splitting the GET and SET calls into two different templates worked perfectly. – Brooks Seymore Dec 20 '12 at 22:37
4

If I'm trying to get the stash in the same template I find using process=end in the stash:get usually works.

{exp:channel:entries channel="work" limit="1"}
Expected: {title} /
{exp:stash:set name="title"}{title}{/exp:stash:set}
{/exp:channel:entries}

{!-- access with process="end" --}
Result: {exp:stash:get name="title" process="end"}

More info on process end in the Stash docs (dev branch, currently v2.3.5)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.