mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-10-31 12:21:36 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			82 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| <?xml version="1.0" encoding="iso-8859-1"?>
 | |
| <!-- $Revision$ -->
 | |
|    <sect1 id="plugins.compiler.functions"><title>Funções Compiladoras</title>
 | |
|     <para>
 | |
|      Funções compiladoras só são chamadas durante a compilação do template.
 | |
|      Elas são úteis para injeção de código PHP ou conteúdo estático time-sensitive
 | |
|      dentro do template. Se há ambos, uma função 
 | |
|      compiladora e uma função customizável
 | |
|      registrada sob o mesmo nome, a função compiladora tem precedência.
 | |
|     </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>
 | |
|      À função compiladora são passados dois parâmetros: 
 | |
|      a tag string de argumento da tag - basicamente, tudo a partir
 | |
|      do nome da função até o delimitador de fechamento, e o objeto da Smarty. É suposto que retorna o código PHP
 | |
|      para ser injetado dentro do template compilado.
 | |
|     </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>função compiladora simples</title>
 | |
|      <programlisting>
 | |
| <?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>
 | |
|       Esta função pode ser chamada em um template da seguinte forma:
 | |
|      </para>
 | |
|      <programlisting>
 | |
| {* esta função é executada somente no tempo de compilação *}
 | |
| {tplheader}</programlisting>
 | |
|      <para>
 | |
|       O código PHP resultante no template compilado seria algo assim:
 | |
|      </para>
 | |
|      <programlisting>
 | |
| <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
 | |
| --> |