0

I am storing site settings using stash and would like to pull out the email address from stash and use it in the EE encode tag. Does anyone know if this is possible?

I have tried a few different things. Lastly this...

{encode="{exp:stash:get name='email'}?subject=Information About a Home" title="Email Us"}

It isn't rendering the stash variable inside the encode tag. Instead, I get the following:

<span data-eeencemail_tzeaewnqdt="1">
    <a href="mailto:?subject=Information About a Home">Email Us</a>
</span>

* EDIT *

How I set the stash:

{!-- CONTACT EMAIL --}
    {exp:stash:email}{contact_email}{/exp:stash:email}

* SOLUTION *

I was able to use this by utilizing the parse tags in stash to get around the parsing order on output.

So instead of this:

{encode="{exp:stash:get name='email'}?subject=Information About a Home" title="Email Us"}

I did this:

{exp:stash:parse}
    {encode="{exp:stash:get name='email'}?subject=Information About a Home" title="Email Us"}
{/exp:stash:parse}

which worked perfectly.

* BETTER SOLUTION *

Even thought the above worked (Which I'm leaving in case someone didn't know about the stash parse tags), @natetronn's solution was much better since it uses the short syntax. Using the short syntax, it becomes this:

{encode="{exp:stash:email}?subject=Information About a Home" title="Email Us"}
3
  • Can you include or link to the Stash code itself?
    – Natetronn
    Feb 23 '16 at 0:44
  • Not sure I'm following... I can output the stash email itself outside of the encode tag. If you are referring to how I set the email, I edited the original question to show that.
    – W3bGuy
    Feb 23 '16 at 0:46
  • I got this working by using the Stash Parse tags. I'll update the OP until an answer can be accepted.
    – W3bGuy
    Feb 23 '16 at 1:13
0

I'm not totally sure if it matters but, I see you're setting your var using the Set shortcut syntax. Try getting using the Get shortcut syntax as well i.e. {exp:stash:email} That is, try not to mix syntaxes.

I'm curious to know if that makes a difference?

3
  • Taking your answer. It works. I got used to using the mixed syntax when using an older version of stash and having problems using short. Thanks for the knock in the head. ;)
    – W3bGuy
    Feb 23 '16 at 1:29
  • Ah, cool. Yeah, for a second there I couldn't understand why the email var wasn't ready to go since it was processed some steps back in the parse order and this before the encode global standard var. Glad it worked for you.
    – Natetronn
    Feb 23 '16 at 1:34
  • It doesn't make any difference which syntax you use to set or get the variable, but you need to be careful when using the same identical tag multiple times - see my answer below. Feb 23 '16 at 10:18
0

I'll assume your variable was SET previously in the parse order.

Were you doing this by any chance?

{!-- test: does this work? --}
{exp:stash:get name='email'}

{encode="{exp:stash:get name='email'}?subject=Information About a Home" title="Email Us"}

If so, you'll have come across a parsing 'feature' in EE whereby identical calls to the same tag causes them to be cached. What happens is that after parsing the first instance, EE replaces the subsequent instances of the tag with markers that gets replaced at the end of parsing, after other tags have been parsed. This can have the unfortunate result that markers netsed inside other tags or passed as parameters get marooned (and since this is usually what you want to do with a stash variable, it causes a problem):

{!-- test: does this work? --}
me@mydomain.com

{encode="M0100749435475676575675?subject=Information About a Home" title="Email Us"}

See this article for a full explanation: http://blog.ericlamb.net/2011/05/expressionengine-and-the-mystery-of-m00o93h7pq09l8x1t49chy01z5j4tt91fgfr/

To stop this happening you can append the word 'random' to the later instances:

{!-- test: does this work? --}
{exp:stash:get name='email'}

{encode="{exp:stash:get name='email' random}?subject=Information About a Home" title="Email Us"}

See: http://www.emarketsouth.com/add-ons/string-plugin/template-tags/#random-parameter

Alternatively you can access the variable as a placeholder variable inside {exp:stash:parse}, and use it as many times as you like:

{exp:stash:parse}

    {!-- test: does this work? --}
    {stash:email}

    {encode="{stash:email}?subject=Information About a Home" title="Email Us"}
{/exp:stash:parse}
2
  • thanks. I didn't need to use these methods as simply using the short syntax worked on this one. I do have another question though. I'll drop a link in here when I finish posting it. Hoping you can shed some light on it for me. :)
    – W3bGuy
    Feb 23 '16 at 14:35

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.