Re: [SMARTY] in_array function

From: Date: Thu, 10 Apr 2003 23:47:00 +0000
Subject: Re: [SMARTY] in_array function
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9213@lists.php.net to get a copy of this message
Sorry that I'm not answering your question, but asking one instead... wouldn't it be possible to do this data assembly in PHP and assign it in a structure that can just be looped through and displayed? The reason things like in_array are not already available is because they shouldn't be needed, and they prompt this kind of templating "abuse" :-) In your case I'd assemble and assign an 'is_linked' array instead of assembling it on-the-fly in the template. /* load the abc's */ $smarty->assign('abc',array('A','B','C','D','E')); /* do some logic to figure this array out */ $smarty->assign('is_linked',array(true,true,false,false,true)); {section name=letter loop=$abc} {if $is_linked[letter]} <a href="coverages.pgp?mode=alpha&letter={$abc[letter]}">{$abc[letter]}</a> {else} {$abc[letter]} {/if} {if !$smarty.section.letter.last} | {/if} {/section} Monte olinux wrote:
Just tried creating my first custom function. very simple in_array() Wonder though, this seems to be too complex for what I'm doing. I'm just print a alpha menu where only letters with results are hyperlinked. Is there anything I should do differently? /* load the abc's */ $smarty->assign('abc',array('A','B','C','D','E')); /* array of letters with results ** retrieved from db in this format ** Array (4) ** 0=> A ** 1=> L ** 2=> M ** 3=> O */ $smarty->assign('broker_coverages_letters',$broker_coverages_letters); ===[ in_array function ]============= /* check that needle / haystack are set */ $in_array = in_array ($params['needle'], $params['haystack']); if (!empty($params['assign'])) { $smarty->assign($params['assign'],$in_array); } ===[ end in_array function ]========= ===[ alphamenu template ]============ {section name=letter loop=$abc} {in_array assign=linkit needle=$abc[letter] haystack=$broker_coverages_letters} {if $linkit} <a href="coverages.pgp?mode=alpha&letter={$abc[letter]}">{$abc[letter]}</a> {else} {$abc[letter]} {/if} {if !$smarty.section.letter.last} | {/if} {/section} ===[ end alphamenu template ]======== Thanks, olinux __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com


« previous php.smarty.general (#9213) next »