[CTLModulemaker (or general smarty) is_'not'selected

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
louisk
Forum Members
Forum Members
Posts: 89
Joined: Wed May 30, 2007 7:40 pm

[CTLModulemaker (or general smarty) is_'not'selected

Post by louisk »

I don't know if this is a CTLModulemaker specific question, of more a general smarty question.

I've made a module with CTLModulemaker and noticed that there is a smarty variable called: $item->is_selected.
I want to use this in my template but I want to show something also when NO/0 item/s is/are selected.

I now have the code

Code: Select all

{foreach from=$itemlist item="item"}
{if $item->is_selected}
........
{/if}
{/forwach}
No I want to show alternative content when no items are selected; (!) note: I don't want to show the not-selected items (because that would result in showing all items).
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: [CTLModulemaker (or general smarty) is_'not'selected

Post by plger »

Right now there's no easy way in to check if any item is selected, but I will add one. Until then, what you could do is iterate through the item to look for a selected one first, and then behave accordingly :

Code: Select all

{assign var="selected_item" value=false}
{foreach from=$itemlist item="item"}
{if $item->is_selected}{assign var="selected_item" value=$item}{/if}
{/foreach}
{if $selected_item}
{$selected_item->name}
{else}
{foreach from=$itemlist item="item"}
...
{/foreach}
{/if}
Post Reply

Return to “Modules/Add-Ons”