1

So, apologies I know this has been covered extensively BUT I've been pulling my hair out all day and still don't get why I can't get this to work.

I simply want to use a stash variable set in one channel entries call as a parameter value for categories in a channel entries call later on in the template.

I've set this in stash:

{!-- set some parameters --}
{exp:channel:entries channel='super_hub' limit='1'}
    ...
    {!-- set the cfp id --}
    {exp:stash:set name='cfpid'}
        {shub_cfp_category:category_id}
    {/exp:stash:set}

Then I'm trying to parse the value in a later channel entries call:

{!-- pull in recent CFPs --}
{exp:channel:entries channel='call_for_papers' limit='3' sort="desc" dynamic='no' category="{exp:stash:get name='cfpid'}" parse="inward"}

But this either doesn't call the right category entries, or doesn't run at all. I've tried different ways of setting the value and calling the value, and attempted using {exp:stash:parse} as well - all with no luck.

It feels like this is a scope issue, but what puzzles me is that I can display the stash value within the content of the second channel entries, but not use it as a parameter value in the call itself.

This seems like such a simple thing and I'm sure I'm doing something daft here. Please can someone help?

EDIT: thought I fixed it with Mark's help, but I've broken it again. Any inclusion of stash:parse just breaks the whole page. Below is the whole code:

{!-- retrieve layout --}
{embed='layouts/.default'}

{!-- set some parameters --}
{exp:channel:entries channel='super_hub' limit='1' parse_depth='2'}

    {!-- set the title --}
    {exp:stash:set name='title'}
        {shub_display_title} |
    {/exp:stash:set}

    {exp:stash:set name='cfpid'}{shub_cfp_category:category_id}{/exp:stash:set}

    {!-- set content --}
    {exp:stash:set name="content"}

        <article>
            <div class="wrapper">

                <header>
                    {!-- Add in display title and associated subtitles --}
                    <h1>{shub_display_title}</h1>
                    {!-- add in sharing buttons --}
                    {cpb_ptl_shr}
                </header>

                <div class="content">
                    <section class="shub">
                        {shub_playa_campaigns}
                            <div class="shubitem{switch=' ie-switch-alpha| ie-switch-beta'}">
                            {exp:switchee variable='{channel_short_name}' parse='inward'}

                                {!-- campaign page --}
                                {case value='campaign_page'}
                                    <div class="item__img">
                                        {if '{campaign_hero_image}' != ''}
                                            {exp:ce_img:single src="{campaign_hero_image}" crop="yes|left,top|0,0"}
                                        {if:else}
                                            {exp:ce_img:single src="/assets/img/bdg/TFO-placeholder-hero.png" crop="yes|left,top|0,0"}
                                        {/if}
                                    </div>
                                    <h3 class="item__header"><a href="{page_url}">CAM {campaign_display_title}</a></h3>
                                    <a href="{page_url}"><div class="item__description">
                                        {exp:ce_str:ing allow_eecode remove_html truncate="200"}{campaign_introductory_copy}{/exp:ce_str:ing}
                                    </div></a>  
                                {/case}

                                {!-- hub page --}
                                {case value='hub_page'}
                                    <div class="item__img">
                                        {if '{hub_hero_image}' != ''}{hub_hero_image}<img src="{url}">{/hub_hero_image}{/if}
                                    </div>
                                    <h3 class="item__header"><a href="{page_url}">HUB {hub_display_title}</a></h3>
                                    <a href="{page_url}"><div class="item__description">
                                        {exp:ce_str:ing allow_eecode remove_html truncate="200"}{hub_introductory_copy}{/exp:ce_str:ing}
                                    </div></a>

                                {/case}

                                {!-- listing page --}
                                {case value='listing_page'}
                                    <div class="item__img">
                                        {if '{listing_hero_image}' != ''}{listing_hero_image}<img src="{url}">{/listing_hero_image}{/if}
                                    </div>
                                    <h3 class="item__header"><a href="{page_url}">LIS {listing_display_title}</a></h3>
                                    <a href="{page_url}"><div class="item__description">    
                                        {exp:ce_str:ing allow_eecode remove_html truncate="200"}{listing_introductory_copy}{/exp:ce_str:ing}
                                    </div></a>
                                {/case}

                            {/exp:switchee}
                            </div>
                        {/shub_playa_campaigns}
                    </section>
                </div> {!-- /.content --}
                {!-- close channel entries --}
                {/exp:channel:entries}

                {!-- secondary content --}
                <div class="secondary">
                    <!-- CFP feed -->
                    <aside>
                        <h2>Call for papers</h2>

                        <div class="cfp-feed">

                        {!-- pull in recent CFPs --}
                        {exp:channel:entries channel='call_for_papers' limit='3' sort="desc" dynamic='no' category="{exp:stash:get name='cfpid'}" parse="inward"}

                            <div class="cfp-feed__item{switch=' ie-switch-alpha| ie-switch-beta'}"> 

                                <div class="cfp-feed__item__img">
                                    {exp:playa:children field="cfp_journal"}
                                        <a href="#{entry_id}">
                                        {!-- <img class="cover" src="/uploads/images/journals/covers/{journal_acronym}.jpg" alt="{title}"/> --}
                                        <img src="http://placehold.it/90x120">
                                        </a>
                                    {/exp:playa:children}
                                </div>

                                <div class="cfp-feed__item__description">
                                    <a href="#{entry_id}">{cfp_display_title}</a><br>
                                    <em>{cfp_journal}{title}{if journal_subtitle}: {journal_subtitle}{/if}{/cfp_journal}</em><br>
                                    {if cfp_deadline}<time datetime="{cfp_deadline format="{DATE_W3C}"}">Deadline: {cfp_deadline format="%j %F %Y"}</time><br>{/if}
                                </div>

                            </div>  
                        {/exp:channel:entries}

                        </div>

                    </aside>

                    <aside class="subject-profile">
                        <h2>Social Media for this subject</h2>
                        <ul class="iconic">
                            <li><i class="fa fa-facebook fa-2x"></i> <a href="#">Facebook</a></li>
                            <li><i class="fa fa-twitter fa-2x"></i> <a href="#">Twitter</a></li>
                        </ul>
                    </aside>

                    <aside class="promotion">
                        <h2>Sign up to stuff</h2>
                        <ul class="iconic">
                            <li><i class="fa fa-envelope"></i> <a href="#">Link to a bulletin or something</a></li>
                            <li><i class="fa fa-rss"></i> <a href="#">Perhaps an RSS feed?</a></li>
                        </ul>
                    </aside>

                </div> <!-- /.secondary -->

            </div> {!-- /.wrapper --}

        </article>


        <footer>
            <div class="wrapper">
                <!-- {cpb_ptl_pub_date} -->
            </div>
        </footer>

    {/exp:stash:set}
6
  • 1
    what is 'shub_cfp_category' just a relate field? also you definitely don't have (disable="categories") in your channel entries tag?
    – Keith
    Feb 4, 2016 at 15:48
  • Does cfpid output an id like you expect it to when run outside the channel entries tag? (i.e.: {exp:stash:get name='cfpid' process='end'} ) Feb 5, 2016 at 1:16
  • Sheferd, for reference the 'shub_cfp_category' is a Lonely Cat field. Romans, yes - when I run stash:get within the content of the channle entries call it outputs '25' which is the category ID. However on some of the variants I've used to try and solve this it has output a long string of bracketed characters. Feb 5, 2016 at 14:27
  • Found one of those long strings again - {6ee64145dfa4ae5926a9c326266d5954506411531} Feb 5, 2016 at 14:59
  • I think i've just seen the problem... I think my stash and channel entry tags are opening and closing in a terrible order Feb 5, 2016 at 15:17

3 Answers 3

0

It's counter-intuitive but EE parses module tags form the outer layer inwards, rather than a block of tags at a time. This is called recursive parsing, or as I like to think of it, peeling an onion:

{!-- this tag is parsed first --}
{exp:channel:entries channel='super_hub' limit='1'}

    {!-- this tag is parsed third - set 'cfpid'  --}
    {exp:stash:set name='cfpid'}
        {shub_cfp_category:category_id}
    {/exp:stash:set}

{/exp:channel:entries}

{!-- this tag is parsed second - 'cfpid' does not yet exist --}
{exp:channel:entries 
   channel='call_for_papers' 
   limit='3' sort="desc" 
   dynamic='no' 
   category="{exp:stash:get name='cfpid'}" 
   parse="inward"
}

   ...

{/exp:channel:entries}

First you need to ensure that 'cfpid' has been set before you use it, then you must ensure that the value you capture has no surrounding whitespace. There are two ways to do this in the same template, both of which use {exp:stash:parse}:

{!-- parse everything inside to a depth of 2 layers --}
{exp:stash:parse parse_depth="2"}
  {exp:channel:entries channel='super_hub' limit='1'}
      {exp:stash:set name='cfpid'}{shub_cfp_category:category_id}{/exp:stash:set}
  {/exp:channel:entries}
{/exp:stash:parse}

{exp:channel:entries 
   channel='call_for_papers' 
   limit='3' sort="desc" 
   dynamic='no' 
   category="{exp:stash:get name='cfpid'}"
   parse="inward"
}

   ...

{/exp:channel:entries}

Or

{exp:channel:entries channel='super_hub' limit='1'}
    {exp:stash:set name='cfpid'}{shub_cfp_category:category_id}{/exp:stash:set}
{/exp:channel:entries}

{!-- delay parsing of this block of tags until the end of parsing --}
{!-- since Stash is doing the parsing, we can use {stash:cfpid} --}
{exp:stash:parse process="end"}
  {exp:channel:entries 
     channel='call_for_papers' 
     limit='3' sort="desc" 
     dynamic='no' 
     category="{stash:cfpid}"
  }

     ...

  {/exp:channel:entries}
{/exp:stash:parse}
2
  • Posted that comment too early, here's the rest... So, I tried the first option within the page as it is, and the whole page failed and reverted to a 404. Then I tried the second option, and the second channel entries call failed meaning that my sidebar didn't load. I then tried a more exact version of option one - adding a separate channell entries call within a stash:parse just for the purposes of setting the value - and it worked! Problem is now I have two channel entry calls for 'super_hub' and one for 'call_for_papers' - which is one more call than I'd like - but it works! :) :) Feb 5, 2016 at 14:16
  • Ok, so now I'm back to it not working - so going to have to un-do the 'answered' status.Think I might post up the whole code. Feb 5, 2016 at 15:11
0

Ah, if shub_cfp_category is a relationship field try adding 'parse_depth="2"' to your stash tag

{exp:stash:set name='cfpid' parse_depth='2'}
    {shub_cfp_category:category_id}
{/exp:stash:set}

It may not work, but this has definitely caught me out so many times

1
  • Hi Sheferd, thanks for the help. Unfortunately adding the parse_depth parameter to the stash:set didn't work this time. I will certainly bear this in mind on future stash'ings though! Feb 5, 2016 at 14:23
0

So I rearranged the code a bit so the parse order made more sense. You all helped in answering this, but Mark helped me understand so I've given him the green hexagon. :) Thanks all!

Here's the working code:

{!-- retrieve layout --}
{embed='layouts/.default'}

{!-- set some parameters --}
{exp:channel:entries channel='super_hub' limit='1' parse_depth="2"}

    {!-- set the title --}
    {exp:stash:set name='title'}
        {shub_display_title} |
    {/exp:stash:set}

    {!-- grab the cfp category id --}
    {exp:stash:set name='cfpid'}{shub_cfp_category:category_id}{/exp:stash:set}

{!-- close channel entries --}
{/exp:channel:entries}

{!-- set content --}
{exp:stash:set name="content"}

    {!-- set some parameters --}
    {exp:channel:entries channel='super_hub' limit='1'}
    <article>
        <div class="wrapper">

            <header>
                {!-- Add in display title and associated subtitles --}
                <h1>{shub_display_title}</h1>
                {!-- add in sharing buttons --}
                {cpb_ptl_shr}
            </header>

            <div class="content">
                <section class="shub">
                    {shub_playa_campaigns}
                        <div class="shubitem{switch=' ie-switch-alpha| ie-switch-beta'}">
                        {exp:switchee variable='{channel_short_name}' parse='inward'}

                            {!-- campaign page --}
                            {case value='campaign_page'}
                                <div class="item__img">
                                    {if '{campaign_hero_image}' != ''}
                                        {exp:ce_img:single src="{campaign_hero_image}" crop="yes|left,top|0,0"}
                                    {if:else}
                                        {exp:ce_img:single src="/assets/img/bdg/TFO-placeholder-hero.png" crop="yes|left,top|0,0"}
                                    {/if}
                                </div>
                                <h3 class="item__header"><a href="{page_url}">CAM {campaign_display_title}</a></h3>
                                <a href="{page_url}"><div class="item__description">
                                    {exp:ce_str:ing allow_eecode remove_html truncate="200"}{campaign_introductory_copy}{/exp:ce_str:ing}
                                </div></a>  
                            {/case}

                            {!-- hub page --}
                            {case value='hub_page'}
                                <div class="item__img">
                                    {if '{hub_hero_image}' != ''}{hub_hero_image}<img src="{url}">{/hub_hero_image}{/if}
                                </div>
                                <h3 class="item__header"><a href="{page_url}">HUB {hub_display_title}</a></h3>
                                <a href="{page_url}"><div class="item__description">
                                    {exp:ce_str:ing allow_eecode remove_html truncate="200"}{hub_introductory_copy}{/exp:ce_str:ing}
                                </div></a>

                            {/case}

                            {!-- listing page --}
                            {case value='listing_page'}
                                <div class="item__img">
                                    {if '{listing_hero_image}' != ''}{listing_hero_image}<img src="{url}">{/listing_hero_image}{/if}
                                </div>
                                <h3 class="item__header"><a href="{page_url}">LIS {listing_display_title}</a></h3>
                                <a href="{page_url}"><div class="item__description">    
                                    {exp:ce_str:ing allow_eecode remove_html truncate="200"}{listing_introductory_copy}{/exp:ce_str:ing}
                                </div></a>
                            {/case}

                        {/exp:switchee}
                        </div>
                    {/shub_playa_campaigns}
                </section>
            </div> {!-- /.content --}
            {!-- close channel entries --}
            {/exp:channel:entries}


            {!-- secondary content --}
            <div class="secondary">
                <!-- CFP feed -->
                <aside>
                    <h2>Call for papers</h2>

                    <div class="cfp-feed">

                        {!-- pull in recent CFPs --}
                        {exp:channel:entries channel='call_for_papers' limit='3' sort="desc" dynamic='no' category="{exp:stash:get name='cfpid'}" parse="inward"}

                            <div class="cfp-feed__item{switch=' ie-switch-alpha| ie-switch-beta'}"> 

                                <div class="cfp-feed__item__img">
                                    {exp:playa:children field="cfp_journal"}
                                        <a href="#{entry_id}">
                                        {!-- <img class="cover" src="/uploads/images/journals/covers/{journal_acronym}.jpg" alt="{title}"/> --}
                                        <img src="http://placehold.it/90x120">
                                        </a>
                                    {/exp:playa:children}
                                </div>

                                <div class="cfp-feed__item__description">
                                    <a href="#{entry_id}">{cfp_display_title}</a><br>
                                    <em>{cfp_journal}{title}{if journal_subtitle}: {journal_subtitle}{/if}{/cfp_journal}</em><br>
                                    {if cfp_deadline}<time datetime="{cfp_deadline format="{DATE_W3C}"}">Deadline: {cfp_deadline format="%j %F %Y"}</time><br>{/if}
                                </div>

                            </div>

                        {/exp:channel:entries}

                    </div>

                </aside>

                <aside class="subject-profile">
                    <h2>Social Media for this subject</h2>
                    <ul class="iconic">
                        <li><i class="fa fa-facebook fa-2x"></i> <a href="#">Facebook</a></li>
                        <li><i class="fa fa-twitter fa-2x"></i> <a href="#">Twitter</a></li>
                    </ul>
                </aside>

                <aside class="promotion">
                    <h2>Sign up to stuff</h2>
                    <ul class="iconic">
                        <li><i class="fa fa-envelope"></i> <a href="#">Link to a bulletin or something</a></li>
                        <li><i class="fa fa-rss"></i> <a href="#">Perhaps an RSS feed?</a></li>
                    </ul>
                </aside>

            </div> <!-- /.secondary -->

        </div> {!-- /.wrapper --}

    </article>


    <footer>
        <div class="wrapper">
            <!-- {cpb_ptl_pub_date} -->
        </div>
    </footer>

{/exp:stash:set}

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.