mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-04 06:11:37 +01:00 
			
		
		
		
	- updates for new build system - added missing files - corrections from users - revcheck comments for all files - big up to didou and nuno, brilliant work - make test: ok - make: ok
		
			
				
	
	
		
			129 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
			
		
		
	
	
			129 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
<?xml version="1.0" encoding="iso-8859-1"?>
 | 
						|
<!-- $Revision$ -->
 | 
						|
<!-- EN-Revision: 1.2 Maintainer: andreas Status: ready -->
 | 
						|
  <sect1 id="plugins.functions"><title>Template-Funktionen</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>
 | 
						|
    Alle einer Funktion übergebenen Parameter werden in der Variable
 | 
						|
    <parameter>$params</parameter> als assoziatives Array abgelegt. Sie können
 | 
						|
     auf diese Werte entweder direkt mit <varname>$params['start']</varname> zugreifen
 | 
						|
     oder sie mit <varname>extract($params)</varname> in die Symbol-Tabelle importieren.
 | 
						|
</para>
 | 
						|
<para>
 | 
						|
 Die Ausgabe der Funktion wird verwendet, um das Funktions-Tag im Template
 | 
						|
 (<function>fetch</function> Funktion, zum Beispiel) zu ersetzen.
 | 
						|
 Alternativ kann sie auch etwas tun, ohne eine Ausgabe zurückzuliefern
 | 
						|
 (<function>assign</function> Funktion, zum Beispiel).
 | 
						|
</para>
 | 
						|
<para>
 | 
						|
 Falls die Funktion dem Template Variablen zuweisen oder
 | 
						|
 auf eine andere Smarty-Funktionalität zugreifen möchte, kann dazu das
 | 
						|
 übergebene <parameter>$smarty</parameter> Objekt verwendet werden.
 | 
						|
</para>
 | 
						|
<para>
 | 
						|
 
 | 
						|
 Sehen Sie dazu:
 | 
						|
 <link linkend="api.register.function">register_function()</link>,
 | 
						|
  <link linkend="api.unregister.function">unregister_function()</link>.
 | 
						|
</para>
 | 
						|
<para>
 | 
						|
 <example>
 | 
						|
  <title>Funktionsplugin mit Ausgabe</title>
 | 
						|
  <programlisting>
 | 
						|
<![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>
 | 
						|
 
 | 
						|
 Es kann im Template wie folgt angewendet werden:
 | 
						|
</para>
 | 
						|
<programlisting>
 | 
						|
 Question: Will we ever have time travel?
 | 
						|
 Answer: {eightball}.</programlisting>
 | 
						|
 <para>
 | 
						|
  <example>
 | 
						|
   <title>Funktionsplugin ohne Ausgabe</title>
 | 
						|
   <programlisting>
 | 
						|
<![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
 | 
						|
-->
 |