mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-10-31 04:11:37 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			247 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
			
		
		
	
	
			247 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| <?xml version="1.0" encoding="iso-8859-1"?>
 | ||
| <!-- $Revision$ -->
 | ||
|   <sect1 id="template.resources">
 | ||
|    <title>Risorse</title>
 | ||
|    <para>
 | ||
|         I template possono arrivare da varie risorse. Quando fate la display o la
 | ||
|         fetch di un template, o quando fate la include da un altro template,
 | ||
|         fornite un tipo di risorsa, seguito dal percorso appropriato e dal nome
 | ||
|         del template. Se non viene esplicitamente indicato un tipo di risorsa,
 | ||
|         viene utilizzato il valore di  <link
 | ||
| 	linkend="variable.default.resource.type">$default_resource_type</link>.
 | ||
|    </para>
 | ||
|    <sect2 id="templates.from.template.dir">
 | ||
|     <title>Template della $template_dir</title>
 | ||
|     <para>
 | ||
|      I template provenienti dalla $template_dir non hanno bisogno che
 | ||
|      indichiate un tipo di risorsa, sebbene possiate indicare file: per
 | ||
|      coerenza. Basta che forniate il percorso per il template che volete
 | ||
|      usare, relativo alla directory radice $template_dir.
 | ||
|     </para>
 | ||
|     <example>
 | ||
|      <title>uso dei template della $template_dir</title>
 | ||
|      <programlisting role="php">
 | ||
| <![CDATA[
 | ||
| <?php
 | ||
| $smarty->display("index.tpl");
 | ||
| $smarty->display("admin/menu.tpl");
 | ||
| $smarty->display("file:admin/menu.tpl"); // equivale al precedente
 | ||
| ?>
 | ||
| ]]>
 | ||
|      </programlisting>
 | ||
|      <para>
 | ||
|       And from within Smarty template:
 | ||
|      </para>
 | ||
|      <programlisting>
 | ||
| <![CDATA[
 | ||
| {include file="index.tpl"}
 | ||
| {include file="file:index.tpl"} {* equivale al precedente *}
 | ||
| ]]>
 | ||
|      </programlisting>
 | ||
|     </example>
 | ||
|    </sect2>
 | ||
|    <sect2 id="templates.from.any.dir">
 | ||
|     <title>Template da qualsiasi directory</title>
 | ||
|     <para>
 | ||
|      I template che si trovano al di fuori della $template_dir richiedono
 | ||
|      obbligatoriamente che indichiate il tipo di risorsa file: seguito
 | ||
|      dal percorso assoluto e dal nome del template.
 | ||
|     </para>
 | ||
|     <example>
 | ||
|      <title>uso dei template da qualsiasi directory</title>
 | ||
|      <programlisting role="php">
 | ||
| <![CDATA[
 | ||
| <?php
 | ||
| $smarty->display("file:/export/templates/index.tpl");
 | ||
| $smarty->display("file:/path/to/my/templates/menu.tpl");
 | ||
| ?>
 | ||
| ]]>
 | ||
|      </programlisting>
 | ||
|      <para>
 | ||
|       And from within Smarty template:
 | ||
|      </para>
 | ||
|      <programlisting>
 | ||
| <![CDATA[
 | ||
| {include file="file:/usr/local/share/templates/navigation.tpl"}
 | ||
| ]]>
 | ||
| </programlisting>
 | ||
|     </example>
 | ||
| 
 | ||
|     <sect3 id="templates.windows.filepath">
 | ||
|      <title>Percorsi su Windows</title>
 | ||
|      <para>
 | ||
|       Se usate una macchina Windows, i percorsi di solito comprendono
 | ||
|       una lettera di drive (C:) all'inizio del percorso. Accertatevi
 | ||
|       di usare "file:" nel path, per evitare conflitti di namespace e
 | ||
|       ottenere i risultati voluti.
 | ||
|      </para>
 | ||
|      <example>
 | ||
|       <title>uso di template da percorsi di Windows</title>
 | ||
|       <programlisting role="php">
 | ||
| <![CDATA[
 | ||
| <?php
 | ||
| $smarty->display("file:C:/export/templates/index.tpl");
 | ||
| $smarty->display("file:F:/path/to/my/templates/menu.tpl");
 | ||
| ?>
 | ||
| 
 | ||
| {* dall'interno di un template *}
 | ||
| {include file="file:D:/usr/local/share/templates/navigation.tpl"}
 | ||
| ]]>
 | ||
| </programlisting>
 | ||
|      </example>
 | ||
|     </sect3>
 | ||
|    </sect2>
 | ||
| 
 | ||
|    <sect2 id="templates.from.elsewhere">
 | ||
|     <title>Template da altre risorse</title>
 | ||
|     <para>
 | ||
|      Potete ottenere template da qualsiasi risorsa alla quale sia 
 | ||
|      possibile accedere con PHP: database, socket, directory LDAP, e
 | ||
|      cos<6F> via. Potete farlo scrivendo una funzione plugin per le
 | ||
|      risorse e registrandola a Smarty.
 | ||
|     </para>
 | ||
| 
 | ||
|     <para>
 | ||
|      Consultate la sezione <link linkend="plugins.resources">plugin
 | ||
|      risorse</link> per maggiori informazioni sulle funzioni che
 | ||
|      dovrete creare.
 | ||
|     </para>
 | ||
| 
 | ||
|     <note>
 | ||
|      <para>
 | ||
|       Notate che non <20> possibile modificare il comportamento della risorsa
 | ||
|       <literal>file</literal>, ma potete fornire una risorsa che legge i
 | ||
|       template dal filesystem in maniera diversa registrandola con un altro
 | ||
|       nome di risorsa.
 | ||
|      </para>
 | ||
|     </note>
 | ||
|     <example>
 | ||
|      <title>uso di risorse personalizzate</title>
 | ||
|      <programlisting role="php">
 | ||
| <![CDATA[
 | ||
| <?php
 | ||
| // mettete queste funzioni da qualche parte nell'applicazione
 | ||
| function db_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
 | ||
| {
 | ||
|     // fate qui le chiamate al database per ottenere il template
 | ||
|     // e riempire $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)
 | ||
| {
 | ||
|     // qui facciamo una chiamata al db per riempire $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)
 | ||
| {
 | ||
|     // ipotizziamo che tutti i template siano sicuri
 | ||
|     return true;
 | ||
| }
 | ||
| 
 | ||
| function db_get_trusted($tpl_name, &$smarty_obj)
 | ||
| {
 | ||
|     // non usata per i template
 | ||
| }
 | ||
| 
 | ||
| // register the resource name "db"
 | ||
| $smarty->register_resource("db", array("db_get_template",
 | ||
|                                        "db_get_timestamp",
 | ||
|                                        "db_get_secure",
 | ||
|                                        "db_get_trusted"));
 | ||
| 
 | ||
| // uso della risorsa dallo script php
 | ||
| $smarty->display("db:index.tpl");
 | ||
| ?>
 | ||
| ]]>
 | ||
|      </programlisting>
 | ||
|      <para>
 | ||
|       And from within Smarty template:
 | ||
|      </para>
 | ||
|      <programlisting>
 | ||
| <![CDATA[
 | ||
| {include file="db:/extras/navigation.tpl"}
 | ||
| ]]>
 | ||
|      </programlisting>
 | ||
|     </example>
 | ||
|    </sect2>
 | ||
| 
 | ||
|    <sect2 id="default.template.handler.function">
 | ||
|     <title>Funzione di gestione dei template di default</title>
 | ||
|     <para>
 | ||
|      Potete specificare una funzione da usare per ottenere i contenuti
 | ||
|      del template nel caso in cui non sia possibile leggerlo dalla
 | ||
|      risorsa appropriata. Un uso possibile di questa funzione <20> di
 | ||
|      creare al volo template che non esistono.
 | ||
|     </para>
 | ||
|     <example>
 | ||
|      <title>uso della funzione di gestione dei template di default</title>
 | ||
|      <programlisting role="php">
 | ||
| <![CDATA[
 | ||
| <?php
 | ||
| // mettete questa funzione da qualche parte nell'applicazione
 | ||
| 
 | ||
| function make_template ($resource_type, $resource_name, &$template_source, &$template_timestamp, &$smarty_obj)
 | ||
| {
 | ||
| 	if( $resource_type == 'file' ) {
 | ||
| 		if ( ! is_readable ( $resource_name )) {
 | ||
| 			// create il file del template e restituite il contenuto.
 | ||
| 			$template_source = "This is a new template.";
 | ||
| 			$template_timestamp = time();
 | ||
| 			$smarty_obj->_write_file($resource_name,$template_source);
 | ||
| 			return true;
 | ||
| 		}
 | ||
|     } else {
 | ||
| 		// non <20> un file
 | ||
| 		return false;
 | ||
|     }
 | ||
| }
 | ||
| 
 | ||
| // impostate il gestore di 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
 | ||
| -->
 |