0

The following is part of an embedded template, which is passed {embed:advertisers_entry_id} that contains a string like 34|68|124|:

{!-- Set defaults --}
{exp:stash:recipients}{/exp:stash:recipients}
{exp:stash:user_recipients}no{/exp:stash:user_recipients}

{!-- Set Stash variables for email contact form --}
{exp:stash:set parse_conditionals="yes" parse_tags="yes"}
    {exp:channel:entries
        channel="advertisers"
        disable="categories|category_fields|pagination"
        entry_id="{embed:advertisers_entry_id}"
    }
        {if {absolute_results} == 1}
            {stash:recipients}{if "{advertiser_email}"}{advertiser_email}{if:else}{author}{/if}{/stash:recipients}
        {if:else}
            {stash:user_recipients}yes{/stash:user_recipients}
        {/if}
    {/exp:channel:entries}
{/exp:stash:set}

{!-- Use Stash variables in email contact form --}
{exp:email:contact_form
    charset="utf-8"
    form_class="customer-email-form"
    recipients="{exp:stash:recipients}"
    user_recipients="{stash:user_recipients}"
}
{/exp:email:contact_form}

The goal is to setup the email contact form to send to either one recipient or multiple sender-specified recipients. Unfortunately, the above code is not working properly and I suspect it's a parse order issue.

It seems like the Channel entry loop is not occuring, and thus my Stash variables are not getting set properly for the email contact form.

Questions:

  1. How do I make the Channel entry loop work?
  2. Once the Stash variables are properly set within the Channel entry loop, how do I use it in the email contact form?

I've tried various combinations of parse="inward", process="end", parse_vars="yes", etc. No go.

1

Hmm,

Using {stash:set} in your example will only ever record your last record. You could be better off using {exp:stash:append}

{exp:channel:entries
   channel="advertisers"
   disable="categories|category_fields|pagination"
   entry_id="{embed:advertisers_entry_id}"}
    //This will give a comma separated string
    {exp:stash:append parse_conditionals="yes" parse_tags="yes"}
      {stash:recipients}
        {if {absolute_results} == 1}
          {if advertiser_email}{advertiser_email},{if:else}{author},{/if}
        {/if}
      {/stash:recipients}
    {/exp:stash:append}
     //This is just set on the last entry
     {exp:stash:set name="user_recipients"}
       {if '{absolute_results}' != '1'}yes{/if}
     {/exp:stash:set}
{/exp:channel:entries}

{!-- Use Stash variables in email contact form --}
{exp:stash:parse} //Wrapping this ensures all stash'ing takes place before we use the values.
{exp:email:contact_form
    charset="utf-8"
    form_class="customer-email-form"
    recipients="{exp:stash:recipients}"
    user_recipients="{stash:user_recipients}"
}
{/exp:email:contact_form}
{/exp:stash:parse}

Ignoring the form part for now, output the results:

recipients = {exp:stash:recipients}
users = {stash:user_recipients}

This is all top-of-the-head, so dont take it as verbatim solution :)

5
  • I understand that it will only ever record my last entry. However, with the conditionals I have, it's fine. If there are only one results, it records the email of that one entry. Otherwise, it sets user_recipients multiple times to "yes" (I don't want "yesyesyesyes"). If there was a way to exist the loop, I would do to when I first set user_recipients, – ExpressionEngineNewbie Apr 2 '15 at 6:38
  • I don't see anything particularly different with your code besides changing "set" to "append". So, without even trying, I'm guessing this will have the same problem as I already have. Also, being able to use the Stash as a param in the email contact form is also important for me to know how to do; I'm assuming parse order issues there. – ExpressionEngineNewbie Apr 2 '15 at 6:39
  • Do you get any results from you stash set at all ? If you do, try wrapping the form in {exp:stash:parse} tags – stuartmcd69 Apr 3 '15 at 4:01
  • Can you please update your answer to show how {exp:stash:parse} comes into play? – ExpressionEngineNewbie Apr 7 '15 at 1:49
  • Comment added. Using parse as per the docs: github.com/croxton/Stash/wiki/%7Bexp%3Astash%3Aparse%7D – stuartmcd69 Apr 14 '15 at 1:29

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.