Smarty: Display a random sentence from array
- by Martind
I have a smarty template, that I want to display a random sentence on each reload. I could do it with this:
in php file:
$sentences = array('Hello you', 'Hi mate', 'Welcome');
shuffle($sentences);
$smarty->assign('sentence', $sentences[0]);
in template file:
<h1>{$sentence}</h1>
Is it possible to do all this in the template instead? Since this isn't exactly programming logic but more a presentation logic, i would like it all in the template like so:
<h1>{'Hello you', 'Hi mate', 'Welcome'| selectRandom }</h1>
Something like that?