views:

97

answers:

1

Hi, I can't find the solution of applying modifiers dynamicly in Smarty.

Template - I would like to work this way (example)

{$myVariable|$modifiers}

Php script

$smarty->assign('myVariable', "brumla brumla na drum drum drum");
$smarty->assign('modifiers', "truncate:30|trim");

Or I would like to apply modifiers in php - is there any method for parsing and applying modifiers in php?

Thanks for answers.

+2  A: 

Each Smarty modifier is really PHP function called smarty_modifier_$name(). This function can be called as any other.

So in that example code you'd just do:

<?php
$myVariable = "brumla brumla na drum drum drum";
$myVariable = smarty_modifier_truncate($myVariable, 30);
$myVariable = smarty_modifier_trim($myVariable);
$smarty->assign('myVariable', $myVariable);

Of course you can use call_user_func() to make it more dynamic.

vartec
And what about modifier date_format if I haven't instance of Smarty. This modifier calls smarty object...
Jaroslav Moravec