We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: NB Cycle

Development and Programming

Nicolas Bottari's avatar
Nicolas Bottari
143 posts
16 years ago
Nicolas Bottari's avatar Nicolas Bottari

Based on a question I asked about looping through variables, I created the NB Cycle plugin, which lets you pass a variable, one by one, from a series of variables (i.e., “cycling” though a series of variables).

Useful for OR conditionals, passing tag parameters one after the other, etc. Example use:

{exp:nb_cycle parse="inward" values="whisky|tango|foxtrot"}

    {variable}


{/exp:nb_cycle}

will output:

whisky
tango
foxtrot

Parameters

parse=”inward” REQUIRED if you are using other plugins within the NB cycle tag pair.

values=”whisky|tango|foxtrot” The values to cycle through, separated by a pipe. Values can be anything: id numbers, weblog names, titles, etc. To pass variables containing a pipe (eg. 1|2, together), separate the variables with a comma “,”. eg. values=”1,2|3”

Single variable tag {variable} This tag will be replaced by the current cycle value set in values=”“

Another (more useful) example:

{exp:nb_cycle values="blog|products|catalog" parse="inward"}

    {exp:weblogs:entries weblog="{variable}"}
    {title}

    {/exp:weblog:entries}

{/exp:nb_cycle}

Mini-cycle I threw in a mini-cycle loop, as it might come in handy. Another set of variables can be looped within the {exp:nb_cycle} tag pair.

Example:

{exp:nb_cycle parse="inward" values="whisky|tango|foxtrot"}

    <h2>{variable}</h2>

    <ul>
    {mini_cycle values="blog|products|catalog"}
    <li>{mini_cycle_variable}</li>
    {/mini_cycle}
    </ul>

{/exp:nb_cycle}

would output

<h2>whisky</h2>
<ul>
    <li>blog</li>
    <li>products</li>
    <li>catalog</li>
</ul>

<h2>tango</h2>
<ul>
    <li>blog</li>
    <li>products</li>
    <li>catalog</li>
</ul>

<h2>foxtrot</h2>
<ul>
    <li>blog</li>
    <li>products</li>
    <li>catalog</li>
</ul>

Single variable tag

{mini_cycle_variable} This tag will be replaced by the current cycle value set in values=”“

Documentation can be found here and example using conditionals is suggested in a previous forum post

       
NKT com's avatar
NKT com
124 posts
16 years ago
NKT com's avatar NKT com

Fabulous! Just what i was looking for!

       
NKT com's avatar
NKT com
124 posts
16 years ago
NKT com's avatar NKT com

Would it be possible to support conditionals based on the variable name? So something like this would work?

{if segment_1=="{variable}"} class="current"{/if}
       
NKT com's avatar
NKT com
124 posts
16 years ago
NKT com's avatar NKT com

My mistake. they do work…

{if "{variable}"=="{segment_1}"} class="current"{/if}
       
Nicolas Bottari's avatar
Nicolas Bottari
143 posts
16 years ago
Nicolas Bottari's avatar Nicolas Bottari

Phew! Glad it worked out for you 😉 I was going to point out that

parse="inward"

might solve your problem.

       
Cem Meric's avatar
Cem Meric
210 posts
16 years ago
Cem Meric's avatar Cem Meric

Very useful Nicolas, thanks.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.