Search code examples
expressionenginecategoriesexpressionengine-stash

Working with Stash, Context and Categories in ExpressionEngine


I'm hoping there is a way to use Stash Context with Categories, for example, like so:

{exp:channel:entries channel="channel-name" dynamic="no" disable="member_data|pagination"}
    {exp:stash:append_list name='list' parse_tags="yes" save="yes" scope="site" context='{categories}{category_name}{/categories}'}
        {stash:this_title}{title}{/stash:this_title}
        {categories}
            {stash:this_category_name}
                {category_name}
            {/stash:this_category_name}
        {/categories}
    {/exp:stash:append_list}
{/exp:channel:entries}


{exp:stash:get_list name="list" parse_tags="yes" parse_conditionals="yes" context="{this_category_name}"}                   
    <div>
        all my stash variables and html etc.
    </div>
{/exp:stash:get_list}

I know I can do the following though, this would mean that someone would have to edit the template each time a category was added.

{exp:stash:get_list name="list" parse_tags="yes" parse_conditionals="yes" context="category1"}                  
    <div>
        all my stash variables and html etc.
    </div>
{/exp:stash:get_list}


{exp:stash:get_list name="list" parse_tags="yes" parse_conditionals="yes" context="category2"}                  
    <div>
        all my stash variables and html etc.
    </div>
{/exp:stash:get_list}

With that said, my question is: is there anyway to dynamically use Stash context and ExpressionEngine categories?


Solution

  • Any reason why you need to use context? I guess I'm not clear on how you are trying to use get_list to output the data. Would something like this achieve what you need to do?