diff options
author | rvelices <rv-github@modusoptimus.com> | 2006-10-31 03:39:39 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2006-10-31 03:39:39 +0000 |
commit | a26ec603b91981812e6402bae60377168de2364c (patch) | |
tree | 71e3b9f1e1da002639a4d4662522ef28a5caa090 | |
parent | 8c4cb2d09a66e20ca6084eb3c6a9824d4cad7806 (diff) |
template improvement: added merge_block_vars method (instead of creating a
new block iteration, it merges given variables with the last block). This
is a trick available to plugins (it will avoid calling trigger_event
every 2 lines).
git-svn-id: http://piwigo.org/svn/trunk@1587 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r-- | include/template.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/include/template.php b/include/template.php index b262bf46c..f58b7a0e3 100644 --- a/include/template.php +++ b/include/template.php @@ -244,6 +244,30 @@ class Template { } /** + * Block-level variable merge. Merge given variables to the last block + * iteration. This can be called several times per block iteration. + */ + function merge_block_vars($blockname, $vararray) + { + $blocks = explode('.', $blockname); + $blockcount = count($blocks); + $str = '$this->_tpldata'; + for ($i = 0; $i < $blockcount; $i++) + { + $str .= '[\'' . $blocks[$i] . '.\']'; + eval('$lastiteration = isset('.$str.') ? sizeof('.$str.')-1:-1;'); + if ($lastiteration==-1) + { + return false; + } + $str .= '[' . $lastiteration . ']'; + } + $str = $str.'=array_merge('.$str.', $vararray);'; + eval($str); + return true; + } + + /** * Root-level variable assignment. Adds to current assignments, overriding * any existing variable assignment with the same name. */ |