I posted this in the Stash support forum on Devot-ee, but there's more activity over here so I thought I'd try my luck in both locations. Not sure about the etiquette of posting in two forums, so apologies if it bends any noses. Here's my situation:
I have a site in which the user can turn various sections (Books, Screenwriting, News, Events etc) on or off depending on whether they are relevant to them. Whether a specific section is on or off is recorded in a Global Variable—eg. gv_include_books_section (value=[y/n]).
On the homepage I have a few columns, each of which I want to display recent entries from one section or another. The catch of course is that I don’t know in advance which sections will be on or off, AND I don’t want to use entries from the same section in more than one column. My solution is to only show entries from a section if a) it is switched ‘on’ AND b) it hasn’t been used earlier in the template. (a) is easy to check as it’s already stored in a Global Variable, and I’m using Stash to set a flag to record whether a specific section has already been shown.
I’m also using IfElse since these conditionals necessarily consist of if/else chains (Switchee got too complex as all the branchings required multiple nested Switchee tags). As far as I can see the code I have should work, but it doesn’t. I presume the issue is parse order but I'm unsure how to rectify it.
In addition to the template code; the global variables in play are:
gv_include_books_section = “n”
gv_include_screenwriting_section = “y”
gv_include_journalism_section = “y”
The template code is:
{exp:stash:set_value name="books_used" value="0" type="snippet"}
{exp:stash:set_value name="screen_used" value="0" type="snippet"}
{exp:stash:set_value name="journalism_used" value="0" type="snippet"}
{!-- column_1 --}
{exp:ifelse parse="inward"}
{if gv_include_books_section == "y"}
{exp:stash:set_value name="books_used" value="1" type="snippet" replace="yes"}
{snp_home_books}
{if:elseif gv_include_screenwriting_section == "y"}
{exp:stash:set_value name="screen_used" value="1" type="snippet" replace="yes"}
{snp_home_screen}
{if:else}
<section>Oops</section>
{/if}
{/exp:ifelse}
{!-- columm-2 --}
{exp:ifelse parse="inward"}
{if gv_include_screenwriting_section == "y" && screen_used == "0"}
{exp:stash:set_value name="screen_used" value="1" type="snippet" replace="yes"}
{snp_home_screen}
{if:elseif gv_include_journalism_section == "y" && journalism_used == "0"}
{exp:stash:set_value name="journalism_used" value="1" type="snippet" replace="yes"}
{snp_home_journo}
{if:else}
<section>Oops</section>
{/if}
{/exp:ifelse}
By my reckoning column_1 should display content from the screenwriting section (because the Books section is turned off), and column_2 should show the journalism section (because the Screenwriting section has already been used in Column 1). What’s actually happening, however, is that both columns are showing screenwriting content.
Um… help please? Thanks.