smarty ternary modifier plug-in

November 24, 2007 | In: development, php, tutorials

Here is a modifier plug-in that I wrote for smarty that does a simple ternary operation. I would have thought that they would have this built in but from my searches it doesn’t seem to be the case.

function smarty_modifier_ternary($value,$option1,$option2)
{
    return ($value)?$option1:$option2;
}

You can use it like so…

{$post.is_draft|ternary:'draft':'published'}

If you don’t know how to use smarty plug-ins then you can read up here.

Bookmark and Share
blog comments powered by Disqus

Flickr Pics

13th and washington NYC13th and 9th NYC1st st Jersey CityIMG_2813IMG_2814_2IMG_2816IMG_2815Photo_011908_001Photo_122807_001Photo_121107_001