[pLog-svn] r6293 - plog/trunk/class/template

Mark Wu markplace at gmail.com
Fri Apr 4 13:31:04 EDT 2008


Man .. I forgot put the url

http://www.phpinsider.com/smarty-forum/viewtopic.php?t=11605&highlight=nocac
he

This problem/issue is really pissing me off for a long time .

Finally, we have a way to solve it.

Now we can pass the variable that we want it live between
{nocache}{/nocache} block ..

We don't need to pass the variable in action or view again..

Mark

> -----Original Message-----
> From: plog-svn-bounces at devel.lifetype.net 
> [mailto:plog-svn-bounces at devel.lifetype.net] On Behalf Of 
> mark at devel.lifetype.net
> Sent: Saturday, April 05, 2008 1:23 AM
> To: plog-svn at devel.lifetype.net
> Subject: [pLog-svn] r6293 - plog/trunk/class/template
> 
> Author: mark
> Date: 2008-04-04 13:22:55 -0400 (Fri, 04 Apr 2008) New Revision: 6293
> 
> Modified:
>    plog/trunk/class/template/template.class.php
> Log:
> Remove the {dynamic} filter, and replace it with an enhanced 
> {nocache} filter. (It also compatible with the dynamic filter)
> 
> Now, we can cache the "variable" in no cached block. The 
> usage looks like:
> 
> {nocache name="<unique blockname>" <varname1>=$<value1> 
> [...]}...{/nocache} 
> 
> For more information, please see the following url
> 
> Modified: plog/trunk/class/template/template.class.php
> ===================================================================
> --- plog/trunk/class/template/template.class.php	
> 2008-04-04 17:09:55 UTC (rev 6292)
> +++ plog/trunk/class/template/template.class.php	
> 2008-04-04 17:22:55 UTC (rev 6293)
> @@ -27,11 +27,50 @@
>  	// name of the folder where the default template is stored
>  	define( "DEFAULT_TEMPLATE_FOLDER", "default" );
>  	
> -	// Smarty dynamic block function
> -	function smarty_block_dynamic($param, $content, &$smarty) {
> -    	return $content;
> -	}	
> +	/* block nocache
> +	 *
> +	 * usage
> +	 *
> +	 * {nocache}...{/nocache}
> +	 *
> +	 * OR
> +	 *
> +	 * {nocache name="<unique blockname>" 
> <varname1>=$<value1> [...]}...{/nocache}
> +	 */
> +	function smarty_block_nocache($param, $content, 
> &$smarty, &$repeat)
> +	{
> +		static $counter = array();
> +	
> +		if ($repeat)
> +		{
> +			if (!isset($param['name']))
> +				return $content;
>  
> +			$name = $param['name'];
> +	    	unset($param['name']);
> +
> +			if (!isset($counter[$name]))
> +				$counter[$name] = 0;
> +			$counter[$name]++;
> +	
> +			if ($smarty->_cache_including)
> +			{
> +				$param = 
> isset($smarty->_cache_info['cached_vars'][$name]['items'][$cou
> nter[$name]]) ? 
> $smarty->_cache_info['cached_vars'][$name]['items'][$counter[$
> name]] : array();
> +			}
> +			else
> +			{
> +				
> $smarty->_cache_info['cached_vars'][$name]['items'][$counter[$
> name]] = $param;
> +			}
> +	
> +			foreach ($param AS $k => $v)
> +			{
> +				$smarty->_tpl_vars[$k] = $v;
> +			}
> +		}
> +	
> +		return $content;
> +	}
> +
>      /**
>       * \ingroup Template
>       *
> @@ -100,8 +139,8 @@
>              // this helps if php is running in 'safe_mode'
>              $this->use_sub_dirs = false;
>  
> -			// register dynamic block for every 
> template instance
> -			$this->register_block('dynamic', 
> 'smarty_block_dynamic', false);
> +			// register nocache block for every 
> template instance
> +			$this->register_block('nocache', 
> 'smarty_block_nocache', false);
>  			
>  			if( $config->getValue( 
> 'trim_whitespace_output' ))
>  				$this->load_filter( 'output', 
> 'trimwhitespace' );
> 
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://limedaley.com/mailman/listinfo/plog-svn



More information about the pLog-svn mailing list