[Solved] Check if variable is set in listit2

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
musicscore
Power Poster
Power Poster
Posts: 498
Joined: Wed Jan 25, 2006 11:53 am

[Solved] Check if variable is set in listit2

Post 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
Last edited by musicscore on Wed Jun 12, 2013 10:26 am, edited 1 time in total.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: Check if variable is set in listit2

Post 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
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Stikki

Re: Check if variable is set in listit2

Post 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.
Stikki

Re: Check if variable is set in listit2

Post by Stikki »

Just commited fix for this.

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

Against ITEM objects.
musicscore
Power Poster
Power Poster
Posts: 498
Joined: Wed Jan 25, 2006 11:53 am

Re: Check if variable is set in listit2

Post by musicscore »

Thanx you all.
It's working. ::)
Post Reply

Return to “Modules/Add-Ons”