1

I am not very used to stash. My code looks like this:

{exp:channel:entries 
    channel="moebel" 
    orderby="date" 
    sort="desc" 
    dynamic="off" 
    disable="member_data|trackbacks|pagination"
}
    <a href="{path=moebel/{url_title}}" {if url_title == '{segment_2}' OR segment_2 == '' AND count == '1'}class="active"{/if} >{count}</a>

{if count == '1'}
    {exp:stash:set name="myurltitle"}{url_title}{/exp:stash:set}
{/if}                   
{/exp:channel:entries}

This does not work because the variable 'myurltitle' will always be the last url_title of the 10 entries in the channel.

How can I realize this? Thanks!

2 Answers 2

1

One way is to use Switchee, which is perfect for use with Stash and probably good for opening bottles and cans of Tuna as well:

{exp:channel:entries 
    channel="moebel"
}
    {exp:switchee variable="{count}" parse="inward"}
        {case value="1"}
            {exp:stash:set name="myurltitle"}{url_title}{/exp:stash:set}
        {/case}
    {/exp:switchee}                  
{/exp:channel:entries}
1
  • Or the {exp:ifelse} add-on works like Swtichee. Both IfElse and Switchee are from the same developer as Stash, and they all play nicely together.
    – Jay F
    Jan 14, 2014 at 2:41
0

I'm fairly new to using stash myself. Try putting the stash in its own channel loop, with a limit of one entry.

Compare "Basic Example" on this page: https://github.com/croxton/Stash/wiki/%7Bexp%3Astash%3Aset%7D

// One entry to stash your info here - and ONLY the stash info. 
{exp:channel:entries channel="moebel" 
    orderby="date" 
    sort="desc" 
    dynamic="off" 
    disable="member_data|trackbacks|pagination"
    limit="1"
    }
    {exp:stash:set name="myurltitle"}{url_title}{/exp:stash:set}
{/exp:channel:entries}

// The primary loop for everything else here

{exp:channel:entries channel="moebel" 
    orderby="date" 
    sort="desc" 
    dynamic="off" 
    disable="member_data|trackbacks|pagination"
    }
    <a href="{path=moebel/{url_title}}" {if url_title == '{segment_2}' 
    OR segment_2 == '' AND count == '1'}class="active"{/if} >{count}</a>

{/exp:channel:entries}

Also, your last if check {if url_title == '{segment_2}' OR segment_2 == '' AND count == '1'} could use some parentheses for better operation, e.g. {if url_title == '{segment_2}' OR (segment_2 == '' AND count == '1')}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.