Smarty help a better way to do this

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

Smarty help a better way to do this

Post 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!
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

Re: Smarty help a better way to do this

Post by carasmo »

never mind, this doesn't work.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Smarty help a better way to do this

Post 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}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

Re: Smarty help a better way to do this

Post 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}


carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

Re: Smarty help a better way to do this

Post 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}
Post Reply

Return to “The Lounge”