smarty3 - shorten smarty if statements -


i have smarty if statement follows:

<{if $page->geturlname() eq 'big-issues' or $page->geturlname() eq 'polls' or $page->geturlname() eq 'what-we-do' or $action eq 'events' or $action eq 'blogs' or $action eq 'news'}> 

i have compare same statements several time in template. , tedious ugly repeat statements several times. know can cache statements , reuse many times looking if possible this:

<{if $page->geturlname() eq 'big-issues' or 'polls' or 'what-we-do' or 'events' or $action eq 'blogs' or 'news'}> 

like in php do:

$url = array ("big-issues","polls","what-we-do"); $needle = $page->geturlname(); if(in_array($needle, $centered)) {     //do } 

please note dont have access php code template can use smarty. suggestion highly appreciated.

cheers.

actually solution came with.

note: in template have use <{}> instead of {} start smarty. how template set up.

        <{$urlname = ['big-issues','polls','what-we-do']}>         <{$actiontype = ['news','blogs','events']}>          <{foreach item="url" from=$urlname}>             <{if $page->geturlname() eq $url}>                 <{assign var=showblock value=1}>             <{/if}>         <{/foreach}>          <{foreach item="act" from=$actiontype}>             <{if $action eq $act}>                 <{assign var=showblock value=1}>             <{/if}>         <{/foreach}> 

now check many times in html same statements without messing code.

<{if $showblock}>     <div class="block"> <{else}>     <{div class="regular"}> <{/if}> 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -