mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-04 06:11:37 +01:00 
			
		
		
		
	
		
			
	
	
		
			127 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
		
		
			
		
	
	
			127 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| 
								 | 
							
								<?xml version="1.0" encoding="iso-8859-1"?>
							 | 
						|||
| 
								 | 
							
								<!-- $Revision$ -->
							 | 
						|||
| 
								 | 
							
								   <sect1 id="plugins.functions"><title>Funzioni per i template</title>
							 | 
						|||
| 
								 | 
							
								    <funcsynopsis>
							 | 
						|||
| 
								 | 
							
								     <funcprototype>
							 | 
						|||
| 
								 | 
							
								      <funcdef>void <function>smarty_function_<replaceable>name</replaceable></function></funcdef>
							 | 
						|||
| 
								 | 
							
								      <paramdef>array <parameter>$params</parameter></paramdef>
							 | 
						|||
| 
								 | 
							
								      <paramdef>object <parameter>&$smarty</parameter></paramdef>
							 | 
						|||
| 
								 | 
							
								     </funcprototype>
							 | 
						|||
| 
								 | 
							
								    </funcsynopsis>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Tutti gli attributi passati dai template alle funzioni relative sono
							 | 
						|||
| 
								 | 
							
								     contenuti in <parameter>$params</parameter> nella forma di un array
							 | 
						|||
| 
								 | 
							
								     associativo.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     L'output (valore di ritorno) della funzione sostituir<69> il tag della
							 | 
						|||
| 
								 | 
							
								     funzione nel template (ad esempio con la funzione <function>fetch</function>).
							 | 
						|||
| 
								 | 
							
								     In alternativa, la funzione potrebbe semplicemente svolgere qualche
							 | 
						|||
| 
								 | 
							
								     altro compito, senza produrre output (funzione <function>assign</function>).
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Se la funzione deve assegnare variabili al template, o usare qualche
							 | 
						|||
| 
								 | 
							
								     altra funzionalit<69> di Smarty, pu<70> usare per questo l'oggetto
							 | 
						|||
| 
								 | 
							
								     <parameter>$smarty</parameter> che le viene passato.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Vedere anche:
							 | 
						|||
| 
								 | 
							
								     <link linkend="api.register.function">register_function()</link>,
							 | 
						|||
| 
								 | 
							
								     <link linkend="api.unregister.function">unregister_function()</link>.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     <example>
							 | 
						|||
| 
								 | 
							
								      <title>plugin funzione con output</title>
							 | 
						|||
| 
								 | 
							
								      <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								/*
							 | 
						|||
| 
								 | 
							
								 * Smarty plugin
							 | 
						|||
| 
								 | 
							
								 * -------------------------------------------------------------
							 | 
						|||
| 
								 | 
							
								 * File:     function.eightball.php
							 | 
						|||
| 
								 | 
							
								 * Type:     function
							 | 
						|||
| 
								 | 
							
								 * Name:     eightball
							 | 
						|||
| 
								 | 
							
								 * Purpose:  outputs a random magic answer
							 | 
						|||
| 
								 | 
							
								 * -------------------------------------------------------------
							 | 
						|||
| 
								 | 
							
								 */
							 | 
						|||
| 
								 | 
							
								function smarty_function_eightball($params, &$smarty)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    $answers = array('Yes',
							 | 
						|||
| 
								 | 
							
								                     'No',
							 | 
						|||
| 
								 | 
							
								                     'No way',
							 | 
						|||
| 
								 | 
							
								                     'Outlook not so good',
							 | 
						|||
| 
								 | 
							
								                     'Ask again soon',
							 | 
						|||
| 
								 | 
							
								                     'Maybe in your reality');
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    $result = array_rand($answers);
							 | 
						|||
| 
								 | 
							
								    return $answers[$result];
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								</programlisting>
							 | 
						|||
| 
								 | 
							
								     </example>
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     che pu<70> essere usata cos<6F> nel template:
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <programlisting>
							 | 
						|||
| 
								 | 
							
								Question: Will we ever have time travel?
							 | 
						|||
| 
								 | 
							
								Answer: {eightball}.
							 | 
						|||
| 
								 | 
							
								    </programlisting>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     <example>
							 | 
						|||
| 
								 | 
							
								      <title>funzione plugin senza output</title>
							 | 
						|||
| 
								 | 
							
								      <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								/*
							 | 
						|||
| 
								 | 
							
								 * Smarty plugin
							 | 
						|||
| 
								 | 
							
								 * -------------------------------------------------------------
							 | 
						|||
| 
								 | 
							
								 * File:     function.assign.php
							 | 
						|||
| 
								 | 
							
								 * Type:     function
							 | 
						|||
| 
								 | 
							
								 * Name:     assign
							 | 
						|||
| 
								 | 
							
								 * Purpose:  assign a value to a template variable
							 | 
						|||
| 
								 | 
							
								 * -------------------------------------------------------------
							 | 
						|||
| 
								 | 
							
								 */
							 | 
						|||
| 
								 | 
							
								function smarty_function_assign($params, &$smarty)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    if (empty($params['var'])) {
							 | 
						|||
| 
								 | 
							
								        $smarty->trigger_error("assign: missing 'var' parameter");
							 | 
						|||
| 
								 | 
							
								        return;
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    if (!in_array('value', array_keys($params))) {
							 | 
						|||
| 
								 | 
							
								        $smarty->trigger_error("assign: missing 'value' parameter");
							 | 
						|||
| 
								 | 
							
								        return;
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    $smarty->assign($params['var'], $params['value']);
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								      </programlisting>
							 | 
						|||
| 
								 | 
							
								     </example>
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								  </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
							 | 
						|||
| 
								 | 
							
								-->
							 |