Files
smarty/docs/es/programmers/plugins/plugins-compiler-functions.xml
2004-10-07 18:50:52 +00:00

92 lines
2.9 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<sect1 id="plugins.compiler.functions"><title>Funciones Compiladoras</title>
<para>
Las funciones compiladoras solo son llamadas durante la compilación
del template. Estas son útiles para inyectar codigo PHP o contenido
estático time-sensitive dentro del template. Si existen ambas, una
función compiladora y una función habitual registrada bajo el mismo
nombre, la función compiladora tiene precedencia.
</para>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>smarty_compiler_<replaceable>name</replaceable></function></funcdef>
<paramdef>string <parameter>$tag_arg</parameter></paramdef>
<paramdef>object <parameter>&amp;$smarty</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
En las funciones compiladoras son pasados dos parámetros:
la etiqueta string del argumento de la etiqueta - basicamente,
todo a partir del nombre de la función hasta el delimitador del
cierre, y el objeto del Smarty. Es supuesto que retorna el codigo
PHP para ser inyectado dentro del template compilado.
</para>
<para>
Vea también
<link linkend="api.register.compiler.function">register_compiler_function()</link>,
<link linkend="api.unregister.compiler.function">unregister_compiler_function()</link>.
</para>
<example>
<title>Función compiladora simple</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>
Esta función puede ser llamada en un template de la siguiente forma:
</para>
<programlisting>
{* esta función es ejecutada solamente en tiempo de compilación *}
{tplheader}
</programlisting>
<para>
El codigo PHP resultante en el template compilado seria algo asi:
</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
-->