mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-01 21:01:37 +01:00
banana split
This commit is contained in:
123
docs/ru/programmers/plugins/plugins-functions.xml
Normal file
123
docs/ru/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 Functions</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>
|
||||
All attributes passed to template functions from the template are
|
||||
contained in the <parameter>$params</parameter> as an associative
|
||||
array. Either access those values directly, e.g.
|
||||
<varname>$params['start']</varname> or use
|
||||
<varname>extract($params)</varname> to import them into the symbol
|
||||
table.
|
||||
</para>
|
||||
<para>
|
||||
The output (return value) of the function will be substituted in place of the
|
||||
function tag in the template (<function>fetch</function> function, for
|
||||
example). Alternatively, the function can simply perform some other
|
||||
task without any output (<function>assign</function> function).
|
||||
</para>
|
||||
<para>
|
||||
If the function needs to assign some variables to the template or use
|
||||
some other Smarty-provided functionality, it can use the supplied
|
||||
<parameter>$smarty</parameter> object to do so.
|
||||
</para>
|
||||
<para>
|
||||
See also:
|
||||
<link linkend="api.register.function">register_function()</link>,
|
||||
<link linkend="api.unregister.function">unregister_function()</link>.
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>function plugin with output</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);
|
||||
return $answers[$result];
|
||||
}
|
||||
?></programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
which can be used in the template as:
|
||||
</para>
|
||||
<programlisting>
|
||||
Question: Will we ever have time travel?
|
||||
Answer: {eightball}.</programlisting>
|
||||
<para>
|
||||
<example>
|
||||
<title>function plugin without output</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