mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-27 18:31:36 +01:00
banana split
This commit is contained in:
123
docs/de/programmers/plugins/plugins-functions.xml
Normal file
123
docs/de/programmers/plugins/plugins-functions.xml
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision$ -->
|
||||
<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>
|
||||
<?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);
|
||||
echo $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>
|
||||
<?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)
|
||||
{
|
||||
extract($params);
|
||||
|
||||
if (empty($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($var, $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
|
||||
-->
|
||||
Reference in New Issue
Block a user