mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-04 06:11:37 +01:00 
			
		
		
		
	
		
			
	
	
		
			92 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
		
		
			
		
	
	
			92 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| 
								 | 
							
								<?xml version="1.0" encoding="iso-8859-1"?>
							 | 
						|||
| 
								 | 
							
								<!-- $Revision$ -->
							 | 
						|||
| 
								 | 
							
								   <sect1 id="plugins.compiler.functions"><title>Funzioni di Compilazione</title>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Le funzioni di compilazione sono chiamate solo durante la compilazione
							 | 
						|||
| 
								 | 
							
								     del template. Sono utili per inserire nel template codice PHP o 
							 | 
						|||
| 
								 | 
							
								     contenuto statico dipendente dal momento (ad es. l'ora). Se esistono una
							 | 
						|||
| 
								 | 
							
								     funzione di compilazione e una funzione personalizzata registrate sotto
							 | 
						|||
| 
								 | 
							
								     lo stesso nome, la funzione di compilazione ha la precedenza.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <funcsynopsis>
							 | 
						|||
| 
								 | 
							
								     <funcprototype>
							 | 
						|||
| 
								 | 
							
								      <funcdef>mixed <function>smarty_compiler_<replaceable>name</replaceable></function></funcdef>
							 | 
						|||
| 
								 | 
							
								      <paramdef>string <parameter>$tag_arg</parameter></paramdef>
							 | 
						|||
| 
								 | 
							
								      <paramdef>object <parameter>&$smarty</parameter></paramdef>
							 | 
						|||
| 
								 | 
							
								     </funcprototype>
							 | 
						|||
| 
								 | 
							
								    </funcsynopsis>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Alla funzione di compilazione vengono passati due parametri: la stringa
							 | 
						|||
| 
								 | 
							
								     che rappresenta l'argomento tag - fondamentalmente, tutto dal nome della
							 | 
						|||
| 
								 | 
							
								     funzione fino al delimitatore finale, e l'oggetto Smarty. Ci si aspetta
							 | 
						|||
| 
								 | 
							
								     che la funzione restituisca il codice PHP da inserire nel template
							 | 
						|||
| 
								 | 
							
								     compilato.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     See also
							 | 
						|||
| 
								 | 
							
								     <link linkend="api.register.compiler.function">register_compiler_function()</link>,
							 | 
						|||
| 
								 | 
							
								     <link linkend="api.unregister.compiler.function">unregister_compiler_function()</link>.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <example>
							 | 
						|||
| 
								 | 
							
								     <title>semplice funzione di compilazione</title>
							 | 
						|||
| 
								 | 
							
								     <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								/*
							 | 
						|||
| 
								 | 
							
								 * Smarty plugin
							 | 
						|||
| 
								 | 
							
								 * -------------------------------------------------------------
							 | 
						|||
| 
								 | 
							
								 * File:     compiler.tplheader.php
							 | 
						|||
| 
								 | 
							
								 * Type:     compiler
							 | 
						|||
| 
								 | 
							
								 * Name:     tplheader
							 | 
						|||
| 
								 | 
							
								 * Purpose:  Output header containing the source file name and
							 | 
						|||
| 
								 | 
							
								 *           the time it was compiled.
							 | 
						|||
| 
								 | 
							
								 * -------------------------------------------------------------
							 | 
						|||
| 
								 | 
							
								 */
							 | 
						|||
| 
								 | 
							
								function smarty_compiler_tplheader($tag_arg, &$smarty)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    return "\necho '" . $smarty->_current_file . " compiled at " . date('Y-m-d H:M'). "';";
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								</programlisting>
							 | 
						|||
| 
								 | 
							
								     <para>
							 | 
						|||
| 
								 | 
							
								      Questa funzione pu<70> essere chiamata dal template in questo modo:
							 | 
						|||
| 
								 | 
							
								     </para>
							 | 
						|||
| 
								 | 
							
								     <programlisting>
							 | 
						|||
| 
								 | 
							
								{* questa funzione viene eseguita solo al momento della compilazione *}
							 | 
						|||
| 
								 | 
							
								{tplheader}
							 | 
						|||
| 
								 | 
							
								     </programlisting>
							 | 
						|||
| 
								 | 
							
								     <para>
							 | 
						|||
| 
								 | 
							
								      Il codice PHP risultante nel template compilato sar<61> qualcosa di questo tipo:
							 | 
						|||
| 
								 | 
							
								     </para>
							 | 
						|||
| 
								 | 
							
								     <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								echo 'index.tpl compiled at 2002-02-20 20:02';
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								     </programlisting>
							 | 
						|||
| 
								 | 
							
								    </example>
							 | 
						|||
| 
								 | 
							
								   </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
							 | 
						|||
| 
								 | 
							
								-->
							 |