Page 1 of 1

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

Posted: Mon Sep 14, 2009 2:58 pm
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).

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

Posted: Sun Sep 20, 2009 1:28 pm
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}