diff --git a/NEWS b/NEWS index 20d4b8f2..9d8d395e 100644 --- a/NEWS +++ b/NEWS @@ -1,8 +1,9 @@ - - added assign attribute to insert function (Monte) - - added assign attribute to fetch function (Monte) - - fixed bug with fetch testing for file with http address (Monte) - - added assign attribute to math function (Monte) - - added assign attribute to counter function (Monte) + - added custom cache handling function ability (Monte) + - added assign attribute to insert function, documented (Monte) + - added assign attribute to fetch function, documented (Monte) + - fixed bug with fetch testing for local file when http address (Monte) + - added assign attribute to math function, documented (Monte) + - added assign attribute to counter function, documented (Monte) - fixed bug with counter and skipval setting (Monte) - made {config_load ...} merge globals from each config file only once per scope, thus avoiding several problems. (Andrei) @@ -15,7 +16,7 @@ blocks. (Andrei, Alexander Belonosov) - added 'field_array' attribute to html_select_time function. (Andrei, Michael Caplan) - - dpcumented {section} "max" attribute. (Monte) + - documented {section} "max" attribute. (Monte) - fixed notice message in Smarty_Compiler.class.php. (Monte) - fixed bug with clear_cache introduced in 1.4.6, third parameter should default to null. (Monte) diff --git a/Smarty.class.php b/Smarty.class.php index 0462eb94..0d7a88b6 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -500,11 +500,11 @@ class Smarty { global $HTTP_SERVER_VARS, $QUERY_STRING, $HTTP_COOKIE_VARS; - if ($this->debugging_ctrl == 'URL' + if (!$this->debugging && $this->debugging_ctrl == 'URL' && (!empty($QUERY_STRING) && strstr($QUERY_STRING, $this->_smarty_debug_id))) { $this->debugging = true; } - + if ($this->debugging) { // capture time for debugging info $debug_start_time = $this->_get_microtime(); @@ -1272,13 +1272,13 @@ function _run_insert_handler($args) if (!empty($this->cache_handler_func)) { // use cache_read_handler function - return($$this->cache_handler_func('read', $tpl_file, $cache_id, $compile_id, $results, $this)); + $$this->cache_handler_func('read', $tpl_file, $cache_id, $compile_id, $results, $this); } else { // use local file cache $cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id); - return ($results = $this->_read_file($cache_file)); + $results = $this->_read_file($cache_file); } diff --git a/docs.sgml b/docs.sgml index 14772113..eaecbbbc 100644 --- a/docs.sgml +++ b/docs.sgml @@ -2192,6 +2192,14 @@ pass=foobar n/a The name of the insert function (insert_name) + + assign + string + No + n/a + The name of the template variable the output will + be assigned to + [var ...] [var type] @@ -2207,7 +2215,11 @@ pass=foobar run into the situation where it is impossible to pass data to a template before the template is executed because there is info in the template needed to aquire the data, kind of a catch 22. The insert tag is a way - to callback a function in PHP during runtime of the template. + to callback a function in PHP during runtime of the template. The + difference between insert tags and custom functions is that insert + tags are not cached when you have template caching enabled. They + will be executed on every invocation of the template. Let's say you have a template with a banner slot at the top of the page. The @@ -2240,6 +2252,18 @@ pass=foobar and display the returned results in place of the insert tag. + If you supply the special "assign" attribute, the output of the + insert tag will be assigned to this template variable instead of + being output to the template. NOTE: assiging the output to a template + variable isn't too useful with caching enabled. (added to Smarty + 1.5.0) + + + The Smarty object is passed as the second argument. This way you + can reference and modify information in the Smarty object from + within the insert function. (added in 1.4.5) + + TECHNICAL NOTE: It is possible to have portions of the template not cached. If you have caching turned on, insert tags will not be cached. They will run @@ -2247,11 +2271,6 @@ pass=foobar pages. This works good for things like banners, polls, live weather, search results, user feedback areas, etc. - - NOTE: As of Smarty 1.4.5, the Smarty object is passed as the second - argument. This way you can reference and modify information in the - Smarty object from within the insert function. - if,elseif,else @@ -3152,6 +3171,14 @@ The value of $name is Bob. true Whether or not to print the value + + assign + string + No + n/a + the template variable the output will be assigned + to + @@ -3163,6 +3190,11 @@ The value of $name is Bob. supplying a unique id for each one. If you do not supply an id, the default id will be used. counter was added to Smarty 1.4.0. + + If you supply the special "assign" attribute, the output of the + counter function will be assigned to this template variable instead of + being output to the template. (new in Smarty 1.5.0) + counter @@ -3211,17 +3243,29 @@ OUTPUT: n/a the file, http or ftp site to fetch + + assign + string + No + n/a + the template variable the output will be assigned + to + - fetch allows the template designer to fetch files from the local - file system, http, or ftp and display the contents. If the file - name begins with "http://", the web site page will be fetched and - displayed. If the file name begins with "ftp://", the file will be - fetched from the ftp server and displayed. For local files, the full - system file path must be given, or a path relative to the executed - php script. + fetch is used to fetch files from the local file system, http, or + ftp and display the contents. If the file name begins with + "http://", the web site page will be fetched and displayed. If the + file name begins with "ftp://", the file will be fetched from the + ftp server and displayed. For local files, the full system file + path must be given, or a path relative to the executed php script. + + + If you supply the special "assign" attribute, the output of the + fetch function will be assigned to this template variable instead of + being output to the template. (new in Smarty 1.5.0) TECHNICAL NOTE: This will not support http redirects, be sure to @@ -3241,11 +3285,17 @@ OUTPUT: {fetch file="/export/httpd/www.domain.com/docs/navbar.js"} {* embed some weather text in your template from another web site *} -{fetch file="http://www.myweather.com/cgi-bin/getweather?zipcode=68502"} +{fetch file="http://www.myweather.com/68502/"} {* fetch a news headline file via ftp *} {fetch file="ftp://user:password@ftp.domain.com/path/to/currentheadlines.txt"} +{* assign the fetched contents to a template variable *} +{fetch file="http://www.myweather.com/68502/" assign="weather"} +{if $weather ne ""} + <b>{$weather}</b> +{/if} + @@ -3926,6 +3976,13 @@ OUTPUT: n/a equation variable value + + assign + string + No + n/a + template variable the output will be assigned to + [var ...] numeric @@ -3946,6 +4003,11 @@ OUTPUT: srans and tan are all valid operators. Check the PHP documenation for further information on these math functions. + + If you supply the special "assign" attribute, the output of the + math function will be assigned to this template variable instead of + being output to the template. + math diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 0462eb94..0d7a88b6 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -500,11 +500,11 @@ class Smarty { global $HTTP_SERVER_VARS, $QUERY_STRING, $HTTP_COOKIE_VARS; - if ($this->debugging_ctrl == 'URL' + if (!$this->debugging && $this->debugging_ctrl == 'URL' && (!empty($QUERY_STRING) && strstr($QUERY_STRING, $this->_smarty_debug_id))) { $this->debugging = true; } - + if ($this->debugging) { // capture time for debugging info $debug_start_time = $this->_get_microtime(); @@ -1272,13 +1272,13 @@ function _run_insert_handler($args) if (!empty($this->cache_handler_func)) { // use cache_read_handler function - return($$this->cache_handler_func('read', $tpl_file, $cache_id, $compile_id, $results, $this)); + $$this->cache_handler_func('read', $tpl_file, $cache_id, $compile_id, $results, $this); } else { // use local file cache $cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id); - return ($results = $this->_read_file($cache_file)); + $results = $this->_read_file($cache_file); }