mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-03 13:51:36 +01:00 
			
		
		
		
	
		
			
	
	
		
			240 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
		
		
			
		
	
	
			240 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| 
								 | 
							
								<?xml version="1.0" encoding="iso-8859-1"?>
							 | 
						|||
| 
								 | 
							
								<!-- $Revision$ -->
							 | 
						|||
| 
								 | 
							
								  <sect1 id="template.resources">
							 | 
						|||
| 
								 | 
							
								   <title>Recursos</title>
							 | 
						|||
| 
								 | 
							
								   <para>
							 | 
						|||
| 
								 | 
							
								  Los templates pueden venir de una variedad de fuentes. Cuando usted 
							 | 
						|||
| 
								 | 
							
								  muestra un template con (display) o (fetch), o incluye un template 
							 | 
						|||
| 
								 | 
							
								  dentro de otro template, usted suministra un tipo de recurso, seguido 
							 | 
						|||
| 
								 | 
							
								  por la ruta correcta y el nombre del template.
							 | 
						|||
| 
								 | 
							
								  Si un recurso no es dado explicitamente el valor de
							 | 
						|||
| 
								 | 
							
								  <link linkend="variable.default.resource.type">$default_resource_type</link>
							 | 
						|||
| 
								 | 
							
								  es asumido.
							 | 
						|||
| 
								 | 
							
								   </para>
							 | 
						|||
| 
								 | 
							
								   <sect2 id="templates.from.template.dir">
							 | 
						|||
| 
								 | 
							
								    <title>Templates partiendo del $template_dir</title>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Los templates desde el $template_dir no requieren recursos del 
							 | 
						|||
| 
								 | 
							
								     template, aunque usted puede usar el file: resource for 
							 | 
						|||
| 
								 | 
							
								     consistancy(recurso por consistencia). Justamente proporcionando 
							 | 
						|||
| 
								 | 
							
								     la ruta(path) del template que usted quiere usar en relaci<63>n al 
							 | 
						|||
| 
								 | 
							
								     directorio root $template_dir.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <example>
							 | 
						|||
| 
								 | 
							
								     <title>Usando templates partiendo del $template_dir</title>
							 | 
						|||
| 
								 | 
							
								     <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								// desde el script de PHP
							 | 
						|||
| 
								 | 
							
								$smarty->display("index.tpl");
							 | 
						|||
| 
								 | 
							
								$smarty->display("admin/menu.tpl");
							 | 
						|||
| 
								 | 
							
								$smarty->display("file:admin/menu.tpl"); // agual al de arriba
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* dentro del template de Smarty *}
							 | 
						|||
| 
								 | 
							
								{include file="index.tpl"}
							 | 
						|||
| 
								 | 
							
								{include file="file:index.tpl"} {* igual al de arriba *}
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								</programlisting>
							 | 
						|||
| 
								 | 
							
								    </example>
							 | 
						|||
| 
								 | 
							
								   </sect2>
							 | 
						|||
| 
								 | 
							
								   <sect2 id="templates.from.any.dir">
							 | 
						|||
| 
								 | 
							
								    <title>Templates partiendo de cualquier directorio</title>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Los templates de fuera del $template_dir requieren el file: tipo 
							 | 
						|||
| 
								 | 
							
								     de recurso del template, seguido por la ruta absoluta y el nombre 
							 | 
						|||
| 
								 | 
							
								     del template.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <example>
							 | 
						|||
| 
								 | 
							
								     <title>usando templates partiendo de cualquier directorio</title>
							 | 
						|||
| 
								 | 
							
								     <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								// desde el script de PHP
							 | 
						|||
| 
								 | 
							
								$smarty->display("file:/export/templates/index.tpl");
							 | 
						|||
| 
								 | 
							
								$smarty->display("file:/path/to/my/templates/menu.tpl");
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* desde adentro del template Smarty *}
							 | 
						|||
| 
								 | 
							
								{include file="file:/usr/local/share/templates/navigation.tpl"}
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								</programlisting>
							 | 
						|||
| 
								 | 
							
								    </example>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    <sect3 id="templates.windows.filepath">
							 | 
						|||
| 
								 | 
							
								     <title>Rutas de archivos de Windows</title>
							 | 
						|||
| 
								 | 
							
								     <para>
							 | 
						|||
| 
								 | 
							
								      Si usted esta utilizando una maquina con windows, las rutas de 
							 | 
						|||
| 
								 | 
							
								      los archivos normalmente incluyen la letra del drive (C:) en el 
							 | 
						|||
| 
								 | 
							
								      comienzo del nombre de la ruta. Asegurarse de usar "file:" en la 
							 | 
						|||
| 
								 | 
							
								      ruta para evitar conflictos de nombres y poder obtener los 
							 | 
						|||
| 
								 | 
							
								      resultados desados.
							 | 
						|||
| 
								 | 
							
								     </para>
							 | 
						|||
| 
								 | 
							
								     <example>
							 | 
						|||
| 
								 | 
							
								      <title>usando templates con rutas de archivos de windows</title>
							 | 
						|||
| 
								 | 
							
								      <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								// dentro del script de PHP
							 | 
						|||
| 
								 | 
							
								$smarty->display("file:C:/export/templates/index.tpl");
							 | 
						|||
| 
								 | 
							
								$smarty->display("file:F:/path/to/my/templates/menu.tpl");
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* dentro del template de Smarty *}
							 | 
						|||
| 
								 | 
							
								{include file="file:D:/usr/local/share/templates/navigation.tpl"}
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								</programlisting>
							 | 
						|||
| 
								 | 
							
								     </example>
							 | 
						|||
| 
								 | 
							
								    </sect3>
							 | 
						|||
| 
								 | 
							
								   </sect2>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								   <sect2 id="templates.from.elsewhere">
							 | 
						|||
| 
								 | 
							
								    <title>Templates partiendo de otras fuentes</title>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Se pueden retomar templates usando cualquier fuente posible a la 
							 | 
						|||
| 
								 | 
							
								     que usted pueda acceder con PHP: base de datos, sockets, LDAP, etc.
							 | 
						|||
| 
								 | 
							
								     Usted puede hacer esto escribiendo las funciones de plugin de recurso 
							 | 
						|||
| 
								 | 
							
								     y registrandolas con Smarty.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Vea la secci<63>n <link linkend="plugins.resources">resource plugins</link>
							 | 
						|||
| 
								 | 
							
								     para mayor informacion sobre las funciones que puede utilizar.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    <note>
							 | 
						|||
| 
								 | 
							
								     <para>
							 | 
						|||
| 
								 | 
							
								     Nota Usted puede activar manualmente el recurso <literal>file</literal>
							 | 
						|||
| 
								 | 
							
								     incrustado, pero no puede suministrar un recurso que busca templates a
							 | 
						|||
| 
								 | 
							
								     partir del sistema de archivos de alguna otra forma registrando bajo 
							 | 
						|||
| 
								 | 
							
								     otro nombre de recurso.
							 | 
						|||
| 
								 | 
							
								     </para>
							 | 
						|||
| 
								 | 
							
								    </note>
							 | 
						|||
| 
								 | 
							
								    <example>
							 | 
						|||
| 
								 | 
							
								     <title>Usando recursos habituales</title>
							 | 
						|||
| 
								 | 
							
								     <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								// ponga estas funciones en algun lugar de su aplicaci<63>n
							 | 
						|||
| 
								 | 
							
								function db_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    // ejecutar la base de datos madar llamar aqu<71> su template,
							 | 
						|||
| 
								 | 
							
								    // poblando el $tpl_source
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    $sql = new SQL;
							 | 
						|||
| 
								 | 
							
								    $sql->query("select tpl_source
							 | 
						|||
| 
								 | 
							
								                   from my_table
							 | 
						|||
| 
								 | 
							
								                  where tpl_name='$tpl_name'");
							 | 
						|||
| 
								 | 
							
								    if ($sql->num_rows) {
							 | 
						|||
| 
								 | 
							
								        $tpl_source = $sql->record['tpl_source'];
							 | 
						|||
| 
								 | 
							
								        return true;
							 | 
						|||
| 
								 | 
							
								    } else {
							 | 
						|||
| 
								 | 
							
								        return false;
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    // ejecutar la base de datos llamar aqu<71> para poblar
							 | 
						|||
| 
								 | 
							
								    // $tpl_timestamp.
							 | 
						|||
| 
								 | 
							
								    $sql = new SQL;
							 | 
						|||
| 
								 | 
							
								    $sql->query("select tpl_timestamp
							 | 
						|||
| 
								 | 
							
								                   from my_table
							 | 
						|||
| 
								 | 
							
								                  where tpl_name='$tpl_name'");
							 | 
						|||
| 
								 | 
							
								    if ($sql->num_rows) {
							 | 
						|||
| 
								 | 
							
								        $tpl_timestamp = $sql->record['tpl_timestamp'];
							 | 
						|||
| 
								 | 
							
								        return true;
							 | 
						|||
| 
								 | 
							
								    } else {
							 | 
						|||
| 
								 | 
							
								        return false;
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								function db_get_secure($tpl_name, &$smarty_obj)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    // asume que todos los templates son seguros
							 | 
						|||
| 
								 | 
							
								    return true;
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								function db_get_trusted($tpl_name, &$smarty_obj)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    // no usar para templates
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// registrar el nombre del recurso "db"
							 | 
						|||
| 
								 | 
							
								$smarty->register_resource("db", array("db_get_template",
							 | 
						|||
| 
								 | 
							
								                                       "db_get_timestamp",
							 | 
						|||
| 
								 | 
							
								                                       "db_get_secure",
							 | 
						|||
| 
								 | 
							
								                                       "db_get_trusted"));
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// usando el recurso a partir del script PHP
							 | 
						|||
| 
								 | 
							
								$smarty->display("db:index.tpl");
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* usando el recurso dentro del template de Smarty *}
							 | 
						|||
| 
								 | 
							
								{include file="db:/extras/navigation.tpl"}
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								</programlisting>
							 | 
						|||
| 
								 | 
							
								    </example>
							 | 
						|||
| 
								 | 
							
								   </sect2>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								   <sect2 id="default.template.handler.function">
							 | 
						|||
| 
								 | 
							
								    <title>Funci<EFBFBD>n manipuladora de Template por default</title>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Usted puede especificar la funci<63>n que ser<65> usada para devolver
							 | 
						|||
| 
								 | 
							
								     el contenido del template dentro del evento del template no puede 
							 | 
						|||
| 
								 | 
							
								     ser retomado desde su recurso. Un uso distinto es para crear 
							 | 
						|||
| 
								 | 
							
								     templates que no existen "on-the-fly" (templates cuyo contenido 
							 | 
						|||
| 
								 | 
							
								     cambia mucho, bastante variable).
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <example>
							 | 
						|||
| 
								 | 
							
								     <title> usando la funci<63>n manipuladora de template por default</title>
							 | 
						|||
| 
								 | 
							
								     <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								// ponga esta función en algun lugar de su aplicación
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								function make_template ($resource_type, $resource_name, &$template_source, &$template_timestamp, &$smarty_obj)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
									if( $resource_type == 'file' ) {
							 | 
						|||
| 
								 | 
							
										if ( ! is_readable ( $resource_name )) {
							 | 
						|||
| 
								 | 
							
											// create the template file, return contents.
							 | 
						|||
| 
								 | 
							
											$template_source = "This is a new template.";
							 | 
						|||
| 
								 | 
							
											$template_timestamp = time();
							 | 
						|||
| 
								 | 
							
											$smarty_obj->_write_file($resource_name,$template_source);
							 | 
						|||
| 
								 | 
							
											return true;
							 | 
						|||
| 
								 | 
							
										}
							 | 
						|||
| 
								 | 
							
								    } else {
							 | 
						|||
| 
								 | 
							
										// not a file
							 | 
						|||
| 
								 | 
							
										return false;
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// defina la función manipuladora por default
							 | 
						|||
| 
								 | 
							
								$smarty->default_template_handler_func = 'make_template';
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								</programlisting>
							 | 
						|||
| 
								 | 
							
								    </example>
							 | 
						|||
| 
								 | 
							
								   </sect2>
							 | 
						|||
| 
								 | 
							
								</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
							 | 
						|||
| 
								 | 
							
								-->
							 |