Page 1 of 1

[Solved] Check if variable is set in listit2

Posted: Tue Jun 11, 2013 6:39 pm
by musicscore
I'm using a template in Listit2 :

Code: Select all

<table>
{foreach from=$items item=item}
<tr>
   <td width="210px"><div class="product">{$item->title|cms_escape}{if isset($item->omschrijving)}
<img class="info" src="images/Info-Icon.png" alt="{$item->omschrijving}" height="15" width="15">{/if}</div></td><td><div class="prijs">€ {$item->prijs}</div></td>
</tr>
{/foreach}
</table>
I want to check if $item->omschrijving has text. If so, an image should be displayed. If not, there should be no image.

Using the template above will always display the image as if $item-omschrijving is always filled with text.

I tryed :

Code: Select all

if isset($item->omschrijving)
if !empty($item->omschrijving)
I read the smarty manual but cannot find the solution.

How can I solve this.

Please help.

Musicscore

Re: Check if variable is set in listit2

Posted: Tue Jun 11, 2013 10:15 pm
by Jo Morg
Possibly $item->omschrijving has an empty string ( "" or '' ) These won't pass the tests.
Try

Code: Select all

{if $item->omschrijving != ''}
or a similar syntax...
HTH

Re: Check if variable is set in listit2

Posted: Tue Jun 11, 2013 10:30 pm
by Stikki
ListIt2 value is always set, there fore isset or empty won't apply.

$item->alias context returns always object presentation of value, there fore what Jo Morg suggested is correct way to go.

{if count($item->alias)} should also validate.

if you want specific return value try:

$item->fielddefs.alias->GetValue('object')
$item->fielddefs.alias->GetValue('string')
$item->fielddefs.alias->GetValue('array')

$item->fielddefs.alias.value returns always string presentation of value.

Re: Check if variable is set in listit2

Posted: Tue Jun 11, 2013 11:18 pm
by Stikki
Just commited fix for this.

isset() and empty() will work in 1.4 and later, in template context.

Against ITEM objects.

Re: Check if variable is set in listit2

Posted: Wed Jun 12, 2013 10:26 am
by musicscore
Thanx you all.
It's working. ::)