mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 19:04:27 +02:00
added assign/unassign custom functions, ability to re-extract tpl_vars
This commit is contained in:
@@ -201,6 +201,30 @@ function smarty_mod_default($string, $default="")
|
||||
return $string;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: smarty_func_assign
|
||||
Purpose: assign a value to a template variable
|
||||
\*======================================================================*/
|
||||
function smarty_func_assign($vars,&$smarty_obj)
|
||||
{
|
||||
extract($vars);
|
||||
$smarty_obj->assign($var,$val);
|
||||
$smarty_obj->_extract = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: smarty_func_unassign
|
||||
Purpose: unassign a template variable
|
||||
\*======================================================================*/
|
||||
function smarty_func_unassign($vars,&$smarty_obj)
|
||||
{
|
||||
extract($vars);
|
||||
$smarty_obj->clear_assign($var);
|
||||
$smarty_obj->_extract = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*============================================*\
|
||||
Custom tag functions
|
||||
\*============================================*/
|
||||
|
@@ -120,7 +120,9 @@ class Smarty
|
||||
'html_select_time' => 'smarty_func_html_select_time',
|
||||
'math' => 'smarty_func_math',
|
||||
'fetch' => 'smarty_func_fetch',
|
||||
'counter' => 'smarty_func_counter'
|
||||
'counter' => 'smarty_func_counter',
|
||||
'assign' => 'smarty_func_assign',
|
||||
'unassign' => 'smarty_func_unassign'
|
||||
);
|
||||
|
||||
var $custom_mods = array( 'lower' => 'strtolower',
|
||||
@@ -160,7 +162,7 @@ class Smarty
|
||||
var $_conf_obj = null; // configuration object
|
||||
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
||||
var $_version = '1.4.2'; // Smarty version number
|
||||
|
||||
var $_extract = false; // flag for custom functions
|
||||
|
||||
/*======================================================================*\
|
||||
Function: Smarty
|
||||
|
@@ -309,7 +309,7 @@ class Smarty_Compiler extends Smarty {
|
||||
$arg_list[] = "'$arg_name' => $arg_value";
|
||||
}
|
||||
|
||||
return "<?php $function(array(".implode(',', (array)$arg_list)."), \$this); ?>";
|
||||
return "<?php $function(array(".implode(',', (array)$arg_list)."), \$this); if(\$this->_extract) { extract(\$this->_tpl_vars); \$this->_extract=false; } ?>";
|
||||
}
|
||||
|
||||
|
||||
|
@@ -120,7 +120,9 @@ class Smarty
|
||||
'html_select_time' => 'smarty_func_html_select_time',
|
||||
'math' => 'smarty_func_math',
|
||||
'fetch' => 'smarty_func_fetch',
|
||||
'counter' => 'smarty_func_counter'
|
||||
'counter' => 'smarty_func_counter',
|
||||
'assign' => 'smarty_func_assign',
|
||||
'unassign' => 'smarty_func_unassign'
|
||||
);
|
||||
|
||||
var $custom_mods = array( 'lower' => 'strtolower',
|
||||
@@ -160,7 +162,7 @@ class Smarty
|
||||
var $_conf_obj = null; // configuration object
|
||||
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
||||
var $_version = '1.4.2'; // Smarty version number
|
||||
|
||||
var $_extract = false; // flag for custom functions
|
||||
|
||||
/*======================================================================*\
|
||||
Function: Smarty
|
||||
|
@@ -309,7 +309,7 @@ class Smarty_Compiler extends Smarty {
|
||||
$arg_list[] = "'$arg_name' => $arg_value";
|
||||
}
|
||||
|
||||
return "<?php $function(array(".implode(',', (array)$arg_list)."), \$this); ?>";
|
||||
return "<?php $function(array(".implode(',', (array)$arg_list)."), \$this); if(\$this->_extract) { extract(\$this->_tpl_vars); \$this->_extract=false; } ?>";
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user