| Line | |
|---|
| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | * Smarty plugin
|
|---|
| 4 | * @package Smarty
|
|---|
| 5 | * @subpackage plugins
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | /**
|
|---|
| 10 | * Smarty {eval} function plugin
|
|---|
| 11 | *
|
|---|
| 12 | * Type: function<br>
|
|---|
| 13 | * Name: eval<br>
|
|---|
| 14 | * Purpose: evaluate a template variable as a template<br>
|
|---|
| 15 | * @link http://smarty.php.net/manual/en/language.function.eval.php {eval}
|
|---|
| 16 | * (Smarty online manual)
|
|---|
| 17 | * @author Monte Ohrt <monte at ohrt dot com>
|
|---|
| 18 | * @param array
|
|---|
| 19 | * @param Smarty
|
|---|
| 20 | */
|
|---|
| 21 | function smarty_function_eval($params, &$smarty)
|
|---|
| 22 | {
|
|---|
| 23 |
|
|---|
| 24 | if (!isset($params['var'])) {
|
|---|
| 25 | $smarty->trigger_error("eval: missing 'var' parameter");
|
|---|
| 26 | return;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | if($params['var'] == '') {
|
|---|
| 30 | return;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | $smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
|
|---|
| 34 |
|
|---|
| 35 | ob_start();
|
|---|
| 36 | $smarty->_eval('?>' . $_var_compiled);
|
|---|
| 37 | $_contents = ob_get_contents();
|
|---|
| 38 | ob_end_clean();
|
|---|
| 39 |
|
|---|
| 40 | if (!empty($params['assign'])) {
|
|---|
| 41 | $smarty->assign($params['assign'], $_contents);
|
|---|
| 42 | } else {
|
|---|
| 43 | return $_contents;
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | /* vim: set expandtab: */
|
|---|
| 48 |
|
|---|
| 49 | ?>
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.