From a26ec603b91981812e6402bae60377168de2364c Mon Sep 17 00:00:00 2001 From: rvelices Date: Tue, 31 Oct 2006 03:39:39 +0000 Subject: 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 --- include/template.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'include/template.php') diff --git a/include/template.php b/include/template.php index b262bf46c..f58b7a0e3 100644 --- a/include/template.php +++ b/include/template.php @@ -243,6 +243,30 @@ class Template { return true; } + /** + * 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. -- cgit v1.2.3