Stash
ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4, ExpressionEngine 5, ExpressionEngine 6
Back to this add-on's main page
View Other Add-ons From Mark Croxton
Are conditionals not allowed within a nested stash list?
Support Request
QB Marketing
|
Posted: 20 January 2014 03:35 PM |
|
|
|
Hi there, Mark. I hope this will be an easy one to solve. Here’s my setup:
{exp:stash:set_list name="main_page_content" parse_tags="yes" save="yes" scope="site" parse_depth="2" context="home"}
{exp:channel:entries channel="{my_main_channel_set}" limit="{my_main_channel_limit}" orderby="{my_main_channel_orderby}" sort="{my_main_channel_sort}" dynamic="{my_main_channel_dynamic}" disable="{my_main_channel_disable}" cache="{my_main_channel_cache}" refresh="{my_main_channel_refresh}"}
{stash:page_seo_title}{exp:ifelse parse="inward"}{if cf_{my_main_channel_prefix}_seo_title}{cf_{my_main_channel_prefix}_seo_title}{if:else}{title}{/if}{/exp:ifelse}{/stash:page_seo_title} {stash:page_seo_description}{cf_{my_main_channel_prefix}_seo_description}{/stash:page_seo_description} {stash:page_seo_keywords}{cf_{my_main_channel_prefix}_seo_keywords}{/stash:page_seo_keywords} {stash:page_seo_image}{cf_{my_main_channel_prefix}_seo_image}{/stash:page_seo_image} {stash:entry_id}{entry_id}{/stash:entry_id}
{exp:stash:set_list:nested name="welcome_message_tabs_{entry_id}" parse_tags="yes"} {cf_{my_main_channel_prefix}_body} {stash:heading}{cf_{my_main_channel_prefix}_body:heading}{/stash:heading} {stash:tab_text}{cf_{my_main_channel_prefix}_body:tab_text}{/stash:tab_text} {stash:body}{cf_{my_main_channel_prefix}_body:body}{/stash:body} {stash:photo}{cf_{my_main_channel_prefix}_body:photo}{/stash:photo} {/cf_{my_main_channel_prefix}_body} {/exp:stash:set_list:nested}
{/exp:channel:entries}
{/exp:stash:set_list}
Then is my embedded layout template, I have:
{exp:stash:get_list name="main_page_content" save="yes" scope="site" context="home" parse_conditionals="yes" prefix="welcome"}
{if welcome:count == "1"}<div class="section-container auto" data-section>{/if}
{exp:stash:get_list:nested name="welcome_message_tabs_{entry_id}" parse_tags="yes" parse_conditionals="yes"} <section{if count == "1"} class="active"{/if}> <p class="title" data-section-title><a href="#panel{count}">{tab_text} {count}</a></p> <div class="content" data-section-content> <div class="row"> {if photo} <div class="large-5 columns"> <img src="{photo}" alt="{heading}" /> </div> {/if} <div class="{if photo}large-7{if:else}large-12{/if} columns"> <h3>{if heading}{heading}{/if}</h3> {body} </div> </div> </div>{!-- /.content --} </section> {/exp:stash:get_list:nested}
{if welcome:count == welcome:total_results}</div>{/if}
{/exp:stash:get_list}
So I’m trying to load a nested grid field that MAY contain heading, tab text, photo and body. Then in the layout, I’m looking to use a couple of conditionals to determine whether there is a photo or not, and if so, create the columns for it, and if not, expand the column within which the text is being placed. But When I view the page, I get PHP errors saying Message: Use of undefined constant photo - assumed ‘photo’. The count inside the nested list also always produces “1”. I tried the prefix parameter on the nested list but that didn’t have any effect. Is there something I’m doing wrong here that leaps out at you? This is my first time trying a nested list. The outer seems to work just fine for me - just the inner isn’t behaving as i expected.
Thanks!
|
|
|
Mark Croxton
|
Posted: 20 January 2014 03:48 PM |
# 1
|
|
Developer
|
As you have a nested list you don’t want to use parse_conditionals on either of your get_lists. When applied to the outer list Stash will try to parse conditionals in the inner too, but with values that don’t exist at that point (hence the error).
You will need to use the prefix parameter on the *inner* list or the iteration variables ({count} etc) from the outer list will overwrite the inner list variables. And make sure that all your variables (including variables in conditionals) in the inner list use the prefix.
|
|
|
QB Marketing
|
Posted: 20 January 2014 03:53 PM |
# 2
|
|
|
I’ll be damned. That solved it! Thanks Mark!
|
|
|
spatafore
|
Posted: 29 November 2014 07:54 PM |
# 3
|
|
|
I have a problem related with this, why this code dont works? if I put the IF OUTSIDE the list dont work, so how’s the way to use the if?
my goal is dont exist any entry in the list , so dont show all that block of code.
any help? thanks
{if "{titulo}"} <div class="table-responsive table-condensed"> <table class="table"> <thead> <tr> <th class="normal">TÃtulo</th> <th>Archivo</th> </tr> </thead> <tbody> {exp:stash:get_list name="documentos" } <tr> <td class="normal">{titulo}</td> <td><a href="{archivo}" target="_blank"><button type="button" class="btn btn-default btn-table">Descargar</button></td></a> </tr> {/exp:stash:get_list} </tbody> </table> </div> {/if}
|
|
|