croxton / Stash

Stash allows you to stash text and snippets of code for reuse throughout your templates.
GNU General Public License v3.0
198 stars 20 forks source link

overwritting stash var while list generation forces new list entry #145

Closed thomcheezy closed 8 years ago

thomcheezy commented 8 years ago
{exp:stash:set_list name="dataEntriesHome" parse_tags="yes"}
{exp:channel:entries entry_id="{exp:catme:getEntriesHome}" parse="inward" disable="category_fields|pagination|member_data"}

{stash:url}my default title{/stash:url}
// HERE
{stash:url}{url_title}{/stash:url}

{stash:title}{title}{/stash:title}
{stash:lead}{article_lead}{/stash:lead}

{/exp:channel:entries}
{/exp:stash:set_list}

at the word HERE, instead of overwritting the stash variable (if possible?) it creates a new entry in my list. for 5 entries from channel:entries tag, I have finally 10 entries in my stash list. what I am doing wrong, or how can I overwrite vars while generating my stash list.

http://expressionengine.stackexchange.com/questions/9521/stash-how-to-overwrite-a-variable-in-set-list

Stash: 3.0.2 EE: 3.3.3

Best, Thomas

croxton commented 8 years ago

Please try using parse="yes" rather than parse_tags="yes", since the former will parse conditionals, variables and tags whereas the later only parses tags.

thomcheezy commented 8 years ago

thx, done. but still same behaviour.

thomcheezy commented 8 years ago
<h1>TEST</h1>
{exp:stash:set_list name="test" parse="yes"}
    {exp:channel:entries entry_id="800|803|798|799"}

    {stash:url}default_url{/stash:url}
    {stash:url}{url_title}{/stash:url}<!-- overwrite -->
    {stash:title}{title}{/stash:title}

    {/exp:channel:entries}
{/exp:stash:set_list}

{exp:stash:get_list name="test"}
    TITLE FROM LIST IS: {title}<br>
{/exp:stash:get_list}

output:

stash_overwrite_output

croxton commented 8 years ago

You must use a conditional to remove the line you don't want. There can only be one instance of a list variable set.

<h1>TEST</h1>
{exp:stash:set_list name="test" parse="yes"}
    {exp:channel:entries entry_id="800|803|798|799"}

        {if cf_my_field == "something"}
            {stash:url}default_url{/stash:url}
        {if:else}
            {stash:url}{url_title}{/stash:url}
        {/if}

        {stash:title}{title}{/stash:title}

    {/exp:channel:entries}
{/exp:stash:set_list}

{exp:stash:get_list name="test"}
    TITLE FROM LIST IS: {title}<br>
{/exp:stash:get_list}
thomcheezy commented 8 years ago

thx. so the answer here (http://expressionengine.stackexchange.com/a/15029/7044) is wrong and is not possible?

croxton commented 8 years ago

No, that simply won't work for a list with multiple rows.

thomcheezy commented 8 years ago

thx!