NinjaCipher:-*-:ro60

smarty ternary modifier plug-in

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.

Del.icio.us Digg BlinkList Furl Ma.gnolia Reddit Spurl

Leave a Reply

You must be logged in to post a comment.