0

I'm passing an embed variable to an email form. The email form can either send an email to one member or multiple members. If the embed variable is just one entry id, then it's an email for one member. If the ember variable is a piped list of entry ids, then it's an email for multiple members.

I'm trying to capture certain values in a Stash variable, but it's not working for me:

{exp:stash:set name="recipients"}{/exp:stash:set}
{exp:stash:set name="user_recipients"}no{/exp:stash:set}

{if {embed:advertisers_entry_id}}
    {exp:channel:entries
        channel="advertisers"
        entry_id="{embed:advertisers_entry_id}"
    }
        {if {absolute_results} == 1}
            {exp:stash:set name="recipients"}
                {author}
            {/exp:stash:set}
        {if:elseif absolute_results > 1}
            {exp:stash:set name="user_recipients"}yes{/exp:stash:set}
        {/if}
    {/exp:channel:entries}
{/if}

I've tried adding parser="inward" to the Channel entry loop and also parse_tags="yes" parse_vars="yes" in the Stash setters. No go.

How do I set Stash variables inside the Channel entry loop?

EDIT 1:

I wrote a test script, based on https://github.com/croxton/Stash/wiki/%7Bexp%3Astash%3Aset%7D#basic-usage:

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

{exp:stash:set name="recipients"}me@domain.com{/exp:stash:set}
{exp:stash:set name="user_recipients"}no{/exp:stash:set}

<h2>title: {exp:stash:title}</h2>
<h2>recipients: {exp:stash:recipients}</h2>
<h2>user_recipients: {exp:stash:user_recipients}</h2>

{exp:stash:title} outputs nothing. {exp:stash:recipients} and {exp:stash:user_recipients} outputs as expected. Does this mean that there is something about the setup of my environment that makes Stash not work as expected?

EDIT 2:

Once I have those variables set, I want to be able to use them in:

{exp:email:contact_form
    charset="utf-8"
    form_class="customer-email-form"
    recipients="{exp:stash:recipients}"
    user_recipients="{exp:stash:user_recipients}"
}

They aren't getting parsed. I have tried adding `parse="inward". No go.

1

Thoroughly untested but this could work (in theory)

{exp:stash:set parse_conditionals="yes" parse_tags="yes"}
{if {embed:advertisers_entry_id}}
    {exp:channel:entries
        channel="advertisers"
        entry_id="{embed:advertisers_entry_id}"
    }
        {if {absolute_results} == 1}
            {stash:recipients}
                {author}
            {/stash:recipients}
        {if:elseif absolute_results > 1}
            {stash:user_recipients}yes{/stash:user_recipients}
        {/if}
    {/exp:channel:entries}
{/if}
{/exp:stash:set}

As for your test script, the {exp:channel:entries} tag is at the same level as your {exp:stash:title} tags hence the output. To address it, put the stash tag above the {exp:channel:entries} tag like this:

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

{exp:stash:set name="recipients"}me@domain.com{/exp:stash:set}
{exp:stash:set name="user_recipients"}no{/exp:stash:set}

<h2>title: {exp:stash:title}</h2>
<h2>recipients: {exp:stash:recipients}</h2>
<h2>user_recipients: {exp:stash:user_recipients}</h2>
| 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.