Smarty: Display a random sentence from array

Posted by Martind on Stack Overflow See other posts from Stack Overflow or by Martind
Published on 2010-04-12T00:04:47Z Indexed on 2010/04/12 0:13 UTC
Read the original article Hit count: 908

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about smarty