tags:

views:

276

answers:

1

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?

A: 

implement smarty function selectRandom then :-)

{selectRandom(1, 2, 3, ...)}
zerkms
Yeh, well, I hoped there was already some function to do that.
Martind
i don't think there is any more laconic way to do this. may be it's possible to use **only smarty builtin** functions but i bet it will be a long-long string with a lot of dirty hacks :-)
zerkms