1

I've just installed Stash. I've got a couple of questions on how to use it.

I'm interested in retrieving the stashed variable and putting it in a variable so I can test it, and take actions depending on the value. How would I do that? (Actually, the retrieved variable is from $_POST, and I've got that retrieval happening, but I can't seem to get it in a variable I can use.)

Is there any way to delete a stashed variable? I couldn't find anything in the docs.

Here's my test code:

Get: {exp:stash:get name="test1" dynamic="yes"}<br/>
Output: {test1}<br/>
{if test1 == 'yyy'}Yipee!{if:else}Frack!{/if}<br/>

Thanks for your help.

4
  • Which version of the docs (add-on) are you looking at?
    – Natetronn
    Apr 4 '13 at 1:45
  • It looks like it's 2.0.9, though that doesn't seem to be explicit in the Tag Reference page. Here's the link: hallmark-design.co.uk/code/stash/tag_reference @Natetronn Apr 4 '13 at 14:24
  • For whatever it's worth I use 2.3.6 from dev branch without issue and the documentation there on Github is very helpful: github.com/croxton/Stash
    – Natetronn
    Apr 4 '13 at 15:31
  • Yes, I'm upgrading as we speak. The question is, Can you do a conditional test on a stashed variable? Should I be setting up a context? Can you give me a simple example of how to do this? Thanks for your help @Natetronn. Apr 4 '13 at 15:36
1

Do you need to store the POST var for reuse or do you just want to use it within a conditional? If so you'd probably find that Switchee gets you on the right track. For example:

{exp:switchee variable="{post:my_var}" parse="inward"}

    {case value="value1|value2"}
        Content to show
    {/case}

    {case value="value3" default="Yes"}
        Content to show
    {/case}

{/exp:switchee}

Note the post: prefix for the Switchee variable.

If you do need to cache the POST var then you can stick it in a Stash variable and then parse that with Switchee:

{exp:switchee variable = "stash:my_var" parse="inward"}

Or, rather than caching the POST var, you could put your stash:set calls inside the Switchee loop and you could cache the template output entirely, which could result in significant performance gains. Without more info it's hard to know which approach would be ideal.

2
  • Thanks @domstubbs. I just need to check on a POST variable and take action on it. The {post:my_var} construction is provided by Switchee, yes? It's not a standard EE thing, right? Looks like a cool add-on. But I got Stash doing what I needed. Apr 4 '13 at 16:23
  • Yep, the post: prefix is a Switchee feature.
    – Dom Stubbs
    Apr 5 '13 at 11:09
1

Here's how I got conditionals to work with Stash 2.3.6:

Get: {exp:stash:get name="test1" dynamic="yes" output="yes"}<br/>
Output: {exp:stash:test1}<br/>
{if '{exp:stash:test1}' == 'yyy'}Yipee!{if:else}Frack!{/if}<br/>

I guess you can't really create a variable: they need to come from a channel. So this technique gets test1 from the $_POST array, and now I can test it and take action depending on its value.

4
  • This is great, I had no idea the {exp:stash:test1} syntax existed based on the plugin's docs. Apr 16 '13 at 5:59
  • Yeah, the docs on the website are from the old version. The newer, beta docs are only in the download; not on the web. I wish @MarkCroxton would put them up on the site; would save us from having to find a markdown editor each time. Apr 16 '13 at 17:58
  • The latest docs are actually on the DEV branch of the Stash repo on Github. I've made this the default branch now to avoid confusion :) github.com/croxton/Stash Apr 26 '13 at 18:20
  • @MarkCroxton Much appreciated. Apr 26 '13 at 18:40

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.