mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-10-31 12:21:36 +01:00 
			
		
		
		
	- updates for new build system - added missing files - corrections from users - revcheck comments for all files - big up to didou and nuno, brilliant work - make test: ok - make: ok
		
			
				
	
	
		
			120 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
			
		
		
	
	
			120 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| <?xml version="1.0" encoding="iso-8859-1"?>
 | |
| <!-- $Revision$ -->
 | |
| <!-- EN-Revision: 1.5 Maintainer: andreas Status: ready -->
 | |
|   <sect1 id="caching.cacheable">
 | |
|    <title>Die Ausgabe von cachebaren Plugins Kontrollieren</title>
 | |
|       <para>
 | |
|       Seit Smarty-2.6.0 kann bei der Registrierung angegeben werden ob ein Plugin
 | |
|       cached werden soll. Der dritte Parameter für register_block, register_compiler_function
 | |
|       und register_function heisst <parameter>$cacheable</parameter>, der Standardwert ist TRUE, was in Smarty vor
 | |
|       Version 2.6.0 üblich war.
 | |
|       </para>
 | |
|       <para>
 | |
|        Wenn ein Plugin mit $cacheable=false registriert wird, wird er bei jedem Besuch der Seite aufgerufen, selbst wenn die Site aus dem Cache stammt. Die Pluginfunktion verhält sich ein wenig wie <link linkend="plugins.inserts">insert</link>.
 | |
|       </para>
 | |
|       <para>
 | |
|        Im Gegensatz zu <link linkend="language.function.insert">{insert}</link> werden die Attribute standartmässig nicht gecached. Sie können das caching jedoch mit dem vierten Parameter <parameter>$cache_attrs</parameter> kontrollieren. <parameter>$cache_attrs</parameter> ist ein Array aller Attributnamen die gecached wertden sollen.
 | |
|       </para>
 | |
|      <example>
 | |
|      <title>Preventing a plugin's output from being cached</title>
 | |
|      <programlisting>
 | |
| <![CDATA[
 | |
| <?php
 | |
| require('Smarty.class.php');
 | |
| $smarty = new Smarty;
 | |
| $smarty->caching = true;
 | |
| 
 | |
| function remaining_seconds($params, &$smarty) {
 | |
|     $remain = $params['endtime'] - time();
 | |
|     if ($remain >=0)
 | |
|         return $remain . " second(s)";
 | |
|     else
 | |
|         return "done";
 | |
| }
 | |
| 
 | |
| $smarty->register_function('remaining', 'remaining_seconds', false, array('endtime'));
 | |
| 
 | |
| if (!$smarty->is_cached('index.tpl')) {
 | |
| 	// objekt $obj aus datenbank dem template zuweisen
 | |
|     $smarty->assign_by_ref('obj', $obj);
 | |
| }
 | |
| 
 | |
| $smarty->display('index.tpl');
 | |
| ?>
 | |
| ]]>
 | |
|    </programlisting>
 | |
|    <para>
 | |
|     where index.tpl is:
 | |
|    </para>
 | |
|    <programlisting>
 | |
| <![CDATA[
 | |
| Zeit: {remain endtime=$obj->endtime}
 | |
| ]]>
 | |
| </programlisting>
 | |
|     <para>
 | |
|     Der Wert von $obj->endtime ändert bei jeder Anzeige der Seite, selbst wenn die Seite gecached wurde. Das Objekt $obj wird nur geladen wenn die Seite nicht gecached wurde.
 | |
|     </para>
 | |
|    </example>
 | |
|    <example>
 | |
|    <title>Verhindern dass Template Blöcke gecached werden</title>
 | |
|    <programlisting>
 | |
| <![CDATA[
 | |
| index.php:
 | |
| 
 | |
| <?php
 | |
| require('Smarty.class.php');
 | |
| $smarty = new Smarty;
 | |
| $smarty->caching = true;
 | |
| 
 | |
| function smarty_block_dynamic($param, $content, &$smarty) {
 | |
|     return $content;
 | |
| }
 | |
| $smarty->register_block('dynamic', 'smarty_block_dynamic', false);
 | |
| 
 | |
| $smarty->display('index.tpl');
 | |
| ?>
 | |
| ]]>
 | |
|    </programlisting>
 | |
|    <para>
 | |
|     where index.tpl is:
 | |
|    </para>
 | |
|    <programlisting>
 | |
| <![CDATA[
 | |
| Page created: {"0"|date_format:"%D %H:%M:%S"}
 | |
| 
 | |
| {dynamic}
 | |
| 
 | |
| Now is: {"0"|date_format:"%D %H:%M:%S"}
 | |
| 
 | |
| ... do other stuff ...
 | |
| 
 | |
| {/dynamic}
 | |
| ]]>
 | |
| 
 | |
| </programlisting>
 | |
|     </example>
 | |
|     <para>
 | |
| Um sicherzustellen dass ein Teil eines Templates nicht gecached werden soll, kann dieser Abschnitt in einen {dynamic}...{/dynamic} Block verpackt werden.
 | |
|     </para>
 | |
| </sect1>
 | |
| <!-- Keep this comment at the end of the file
 | |
| Local variables:
 | |
| mode: sgml
 | |
| sgml-omittag:t
 | |
| sgml-shorttag:t
 | |
| sgml-minimize-attributes:nil
 | |
| sgml-always-quote-attributes:t
 | |
| sgml-indent-step:1
 | |
| sgml-indent-data:t
 | |
| indent-tabs-mode:nil
 | |
| sgml-parent-document:nil
 | |
| sgml-default-dtd-file:"../../../../manual.ced"
 | |
| sgml-exposed-tags:nil
 | |
| sgml-local-catalogs:nil
 | |
| sgml-local-ecat-files:nil
 | |
| End:
 | |
| vim600: syn=xml fen fdm=syntax fdl=2 si
 | |
| vim: et tw=78 syn=sgml
 | |
| vi: ts=1 sw=1
 | |
| -->
 |