mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-04 14:21:36 +01:00 
			
		
		
		
	
		
			
	
	
		
			145 lines
		
	
	
		
			6.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
		
		
			
		
	
	
			145 lines
		
	
	
		
			6.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| 
								 | 
							
								<?xml version="1.0" encoding="iso-8859-1"?>
							 | 
						|||
| 
								 | 
							
								<!-- $Revision$ -->
							 | 
						|||
| 
								 | 
							
										<sect1 id="language.function.insert">
							 | 
						|||
| 
								 | 
							
											<title>insert</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>Nome Attributo</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Tipo</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Obbligatorio</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Default</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Descrizione</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                </thead>
							 | 
						|||
| 
								 | 
							
								                <tbody>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>name</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>stringa</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>s<EFBFBD></entry>
							 | 
						|||
| 
								 | 
							
								                        <entry><emphasis>nessuno</emphasis></entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Nome della funzione di insert (insert_name)</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>assign</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>stringa</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>no</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry><emphasis>nessuno</emphasis></entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Nome della variabile del template cui verr<72>
							 | 
						|||
| 
								 | 
							
								                                                assegnato l'output</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>script</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>stringa</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>no</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry><emphasis>nessuno</emphasis></entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Nome dello script php che viene incluso prima
							 | 
						|||
| 
								 | 
							
								                                                della chiamata alla funzione di insert</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>[variabile ...]</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>[tipo variabile]</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>no</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry><emphasis>nessuno</emphasis></entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Variabile da passare alla funzione di insert</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                </tbody>
							 | 
						|||
| 
								 | 
							
								                </tgroup>
							 | 
						|||
| 
								 | 
							
								            </informaltable>
							 | 
						|||
| 
								 | 
							
											<para>
							 | 
						|||
| 
								 | 
							
											I tag insert funzionano praticamente come i tag include, ad
							 | 
						|||
| 
								 | 
							
											eccezione del fatto che i tag insert non vengono messi in
							 | 
						|||
| 
								 | 
							
											cache quando avete il <link linkend="caching">caching</link>
							 | 
						|||
| 
								 | 
							
											del template abilitato. Verranno quindi eseguiti ad ogni
							 | 
						|||
| 
								 | 
							
											chiamata del template.
							 | 
						|||
| 
								 | 
							
											</para>
							 | 
						|||
| 
								 | 
							
								            <para>
							 | 
						|||
| 
								 | 
							
								             Diciamo che abbiamo un template con uno spazio banner in cima
							 | 
						|||
| 
								 | 
							
								             alla pagina. Il banner pu<70> contenere qualsiasi mescolanza di HTML,
							 | 
						|||
| 
								 | 
							
								             immagini, flash, ecc., quindi non possiamo usare un link statico,
							 | 
						|||
| 
								 | 
							
								             e non vogliamo che questo contenuto sia messo in cache con la 
							 | 
						|||
| 
								 | 
							
								             pagina. Ecco quindi l'utilit<69> del tag insert: il template conosce i
							 | 
						|||
| 
								 | 
							
								             valori di #banner_location_id# e #site_id# (presi da un file di 
							 | 
						|||
| 
								 | 
							
								             configurazione), e ha bisogno di chiamare una funzione per ottenere
							 | 
						|||
| 
								 | 
							
								             il contenuto del banner.
							 | 
						|||
| 
								 | 
							
											</para>
							 | 
						|||
| 
								 | 
							
								<example>
							 | 
						|||
| 
								 | 
							
								<title>funzione insert</title>
							 | 
						|||
| 
								 | 
							
								<programlisting>
							 | 
						|||
| 
								 | 
							
								{* esempio di caricamento di un banner *}
							 | 
						|||
| 
								 | 
							
								{insert name="getBanner" lid=#banner_location_id# sid=#site_id#}</programlisting>
							 | 
						|||
| 
								 | 
							
								</example>
							 | 
						|||
| 
								 | 
							
											<para>
							 | 
						|||
| 
								 | 
							
											In questo esempio stiamo usando il nome "getBanner" e passiamo i
							 | 
						|||
| 
								 | 
							
											parametri #banner_location_id# e #site_id#. Smarty cercher<65> una
							 | 
						|||
| 
								 | 
							
											funzione chiamata insert_getBanner() nell'applicazione PHP, passandole
							 | 
						|||
| 
								 | 
							
											i valori di #banner_location_id# e #site_id# come primo argomento
							 | 
						|||
| 
								 | 
							
											in un array associativo. Tutti i nomi di funzioni di insert
							 | 
						|||
| 
								 | 
							
											nell'applicazione devono essere prefissati con "insert_", per evitare
							 | 
						|||
| 
								 | 
							
											possibili conflitti nei nomi di funzione. La nostra funzione
							 | 
						|||
| 
								 | 
							
											insert_getBanner() far<61> qualcosa con i valori passati e restituir<69>
							 | 
						|||
| 
								 | 
							
											il risultato, che verr<72> visualizzato nel templat al posto del tag
							 | 
						|||
| 
								 | 
							
											insert.
							 | 
						|||
| 
								 | 
							
											In questo esempio, Smarty chiamerebbe questa funzione:
							 | 
						|||
| 
								 | 
							
											insert_getBanner(array("lid" => "12345","sid" => "67890"));
							 | 
						|||
| 
								 | 
							
											e visualizzerebbe il risultato restituito al posto del tag insert.
							 | 
						|||
| 
								 | 
							
											</para>
							 | 
						|||
| 
								 | 
							
											<para>
							 | 
						|||
| 
								 | 
							
											Se fornite l'attributo "assign", l'output del tag insert verr<72> 
							 | 
						|||
| 
								 | 
							
											assegnato a questa variabile invece di essere mostrato nel template.
							 | 
						|||
| 
								 | 
							
											NOTA: assegnare l'output ad una variabile non <20> molto utile se il
							 | 
						|||
| 
								 | 
							
											caching <20> abilitato.
							 | 
						|||
| 
								 | 
							
											</para>
							 | 
						|||
| 
								 | 
							
											<para>
							 | 
						|||
| 
								 | 
							
											Se fornite l'attributo "script", questo script verr<72> incluso (una
							 | 
						|||
| 
								 | 
							
											volta sola) prima dell'esecuzione della funzione di insert. Questo
							 | 
						|||
| 
								 | 
							
											caso pu<70> presentarsi quando la funzione di insert pu<70> non esistere
							 | 
						|||
| 
								 | 
							
								                        ancora, e uno script php deve essere quindi incluso per farla 
							 | 
						|||
| 
								 | 
							
								                        funzionare. Il percorso pu<70> essere assoluto o relativo a $trusted_dir.
							 | 
						|||
| 
								 | 
							
								                        Se la security <20> abilitata, lo script deve trovarsi in $trusted_dir.
							 | 
						|||
| 
								 | 
							
											</para>
							 | 
						|||
| 
								 | 
							
											<para>
							 | 
						|||
| 
								 | 
							
											Come secondo argomento viene passato l'oggetto Smarty. In questo
							 | 
						|||
| 
								 | 
							
											modo potete ottenere e modificare informazioni nell'oggetto Smarty
							 | 
						|||
| 
								 | 
							
											dall'interno della funzione di insert.
							 | 
						|||
| 
								 | 
							
											</para>
							 | 
						|||
| 
								 | 
							
											<note>
							 | 
						|||
| 
								 | 
							
											<title>Nota tecnica</title>
							 | 
						|||
| 
								 | 
							
											<para>
							 | 
						|||
| 
								 | 
							
									    E' possibile avere porzioni di template non in cache. Se
							 | 
						|||
| 
								 | 
							
									    avete il <link linkend="caching">caching</link> abilitato,
							 | 
						|||
| 
								 | 
							
									    i tag insert non verranno messi in cache. Verranno quindi
							 | 
						|||
| 
								 | 
							
									    eseguiti dinamicamente ogni volta che la pagina viene creata,
							 | 
						|||
| 
								 | 
							
									    anche se questa si trova in cache. Questo viene utile per cose
							 | 
						|||
| 
								 | 
							
									    come banner, sondaggi, situazione del tempo, risultati di ricerche,
							 | 
						|||
| 
								 | 
							
									    aree di feedback utenti, ecc.
							 | 
						|||
| 
								 | 
							
											</para>
							 | 
						|||
| 
								 | 
							
											</note>
							 | 
						|||
| 
								 | 
							
								</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
							 | 
						|||
| 
								 | 
							
								-->
							 |