Files
smarty/docs/es/designers/language-builtin-functions/language-function-include.xml
2005-11-08 23:37:29 +00:00

184 lines
5.8 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<sect1 id="language.function.include">
<title>include</title>
<informaltable frame="all">
<tgroup cols="5">
<colspec colname="param" align="center" />
<colspec colname="type" align="center" />
<colspec colname="required" align="center" />
<colspec colname="default" align="center" />
<colspec colname="desc" />
<thead>
<row>
<entry>Nombre del Atributo</entry>
<entry>Tipo</entry>
<entry>requerido</entry>
<entry>Default</entry>
<entry>Descripción</entry>
</row>
</thead>
<tbody>
<row>
<entry>file</entry>
<entry>string</entry>
<entry>Si</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>El nombre del archivo de template a Incluir.</entry>
</row>
<row>
<entry>assign</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>El nombre de una variable que contendra toda la
salida del template.</entry>
</row>
<row>
<entry>[var ...]</entry>
<entry>[var type]</entry>
<entry>No</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>Variable para pasar localmente a el template</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
Las etiquetas {include} son usadas para incluir otros templates en
el template actual. Cualquier variable disponible en el template
actual, también esta disponible dentro del template incluido.
La etiqueta {include} debe tener el atributo "file", el cual contiene
la ruta del archivo a incluir.
</para>
<para>
Usted puede opcionalmente pasar el atributo <emphasis>'assign'</emphasis>,
el cual especificara el nombre de una variable de template para el cual
contendra toda la salida de {include} en vez de mostrarla.
</para>
<example>
<title>funcion {include}</title>
<programlisting>
<![CDATA[
<html>
<head>
<title>{$title}</title>
</head>
<body>
{include file="page_header.tpl"}
{* el cuerpo del template va aqui *}
{include file="/$tpl_name.tpl"} <-- will replace $tpl_name with value
{include file="page_footer.tpl"}
</body>
</html>
]]>
</programlisting>
</example>
<para>
Usted también puede pasar variables al template incluidas como
atributos. Cualquier variable pasada al template incluidas como
atributos estan disponibles solamente dentro el espacio del template.
Las variables pasadas como atributos sobreescriben a las variables
del template actual, en el caso en el que estas tengan el mismo nombre.
</para>
<example>
<title>Función {include} pasando variables</title>
<programlisting>
<![CDATA[
{include file="header.tpl" title="Main Menu" table_bgcolor="#c0c0c0"}
{* el cuerpo del template va aqui *}
{include file="footer.tpl" logo="http://my.example.com/logo.gif"}
]]>
</programlisting>
<para>Donde header.tpl puede ser</para>
<programlisting>
<![CDATA[
<table border='1' width='100%' bgcolor='{$table_bgcolor|default:"#0000FF"}'>
<tr><td>
<h1>{$title}</h1>
</td></tr>
</table>
]]>
</programlisting>
</example>
<example>
<title>{include} y asignacion de variables</title>
<para>En este ejemplo asignan el contenido de nav.tpl en la variable $navbar,
entonces la salida hasta arriba y hasta abajo de pagina.
</para>
<programlisting>
<![CDATA[
<body>
{include file="nav.tpl" assign="navbar"}
{include file="header.tpl" title="Main Menu" table_bgcolor="#c0c0c0"}
{$navbar}
{* el cuerpo del template va aqui *}
{include file="footer.tpl" logo="http://my.example.com/logo.gif"}
{$navbar}
</body>
]]>
</programlisting>
</example>
<para>
Use la sintaxis de <link linkend="template.resources">template resources</link>
para incluir archivos fuera del directorio
<link linkend="variable.template.dir">$template_dir</link>.
</para>
<example>
<title>Ejemplos de recursos para la función include</title>
<programlisting>
<![CDATA[
{* ruta absoluta *}
{include file="/usr/local/include/templates/header.tpl"}
{* ruta absoluta (lo mismo) *}
{include file="file:/usr/local/include/templates/header.tpl"}
{* ruta absoluta de windows (DEBE usar el prefijo "file:") *}
{include file="file:C:/www/pub/templates/header.tpl"}
{* incluir a partir del recurso de template denominado "db" *}
{include file="db:header.tpl"}
]]>
</programlisting>
<para>
ver también
<link linkend="language.function.include.php">{include_php}</link>,
<link linkend="language.function.php">{php}</link>,
<link linkend="template.resources">Template Resources</link> y
<link linkend="tips.componentized.templates">Componentized Templates</link>.
</para>
</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
-->