Page 1 of 1

Smarty help a better way to do this

Posted: Fri Jun 15, 2012 5:39 pm
by carasmo
I am using isotope and have an extra field in the news module. It works fine when I hard code the filters. But what if there is no item that matches a filter. I also fixed that too. I did the following ".first" with smarty, it works fine but there must be a shorter/better way:

Code: Select all

{foreach from=$items item=entry name=colorful}
{if $entry->fieldsbyname.filter->value eq 'colorful'}{if $smarty.foreach.colorful.first}
<li><a href="" title="colorful">Colorful</a></li>{/if}
{/if}{/foreach}
Now it works that if there is an entry that has that filter the nav link will show up, if there isn't it won't show up, and it shows up only 1 time. Any better, shorter way to do this? I am smarty illiterate, pretty much...

Thanks!

Re: Smarty help a better way to do this

Posted: Fri Jun 15, 2012 5:43 pm
by carasmo
never mind, this doesn't work.

Re: Smarty help a better way to do this

Posted: Fri Jun 15, 2012 5:52 pm
by calguy1000

Code: Select all

{assign var='tmp' value=0}
{foreach from=$items item=entry name=colorful}
  {if $entry->fieldsbyname.filter->value eq 'colorful' and $tmp == 0}
  <li><a href="" title="colorful">Colorful</a></li>
  {assign var='tmp' value=1}
{/if}
{/foreach}

Re: Smarty help a better way to do this

Posted: Fri Jun 15, 2012 6:01 pm
by carasmo
Dude you rock! Thank you!!!!!

Code: Select all


{assign var='colorful' value=0}
{foreach from=$items item=entry name=colorful}
  {if $entry->fieldsbyname.filter->value eq 'colorful' and $colorful == 0}
  <li><a href="" title="colorful">Colorful</a></li>
  {assign var='colorful' value=1}
{/if}
{/foreach}

{assign var='clean' value=0}
{foreach from=$items item=entry name=clean}
  {if $entry->fieldsbyname.filter->value eq 'clean' and $clean == 0}
  <li><a href="" title="clean">Clean</a></li>
  {assign var='clean' value=1}
{/if}
{/foreach}



Re: Smarty help a better way to do this

Posted: Fri Jun 15, 2012 6:17 pm
by carasmo
I realized that some entries have more than one filter so this worked:

{assign var='colorful' value=0}
{foreach from=$items item=entry name=colorful}
{if $entry->fieldsbyname.filter->value|strstr:'colorful' and $colorful == 0}
<li><a href="" title="colorful">Colorful</a></li>
{assign var='colorful' value=1}
{/if}
{/foreach}