2004-04-13 11:47:32 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
|
|
<!-- $Revision$ -->
|
|
|
|
<sect1 id="plugins.block.functions"><title>Block Functions</title>
|
|
|
|
<funcsynopsis>
|
|
|
|
<funcprototype>
|
|
|
|
<funcdef>void <function>smarty_block_<replaceable>name</replaceable></function></funcdef>
|
|
|
|
<paramdef>array <parameter>$params</parameter></paramdef>
|
|
|
|
<paramdef>mixed <parameter>$content</parameter></paramdef>
|
|
|
|
<paramdef>object <parameter>&$smarty</parameter></paramdef>
|
2004-09-07 08:27:38 +00:00
|
|
|
<paramdef>boolean <parameter>&$repeat</parameter></paramdef>
|
2004-04-13 11:47:32 +00:00
|
|
|
</funcprototype>
|
|
|
|
</funcsynopsis>
|
|
|
|
<para>
|
2006-09-27 03:26:52 +00:00
|
|
|
Block functions are functions of the form:
|
|
|
|
<literal>{func} .. {/func}</literal>. In other words, they enclose a
|
|
|
|
template block and operate on the contents of
|
|
|
|
this block. Block functions take precedence over
|
|
|
|
<link linkend="language.custom.functions">custom functions</link> of
|
|
|
|
the same name, that is, you cannot have both custom function
|
|
|
|
<literal>{func}</literal> and block function
|
|
|
|
<literal>{func}..{/func}</literal>.
|
2004-04-13 11:47:32 +00:00
|
|
|
</para>
|
2006-09-27 03:26:52 +00:00
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem><para>
|
2004-04-13 11:47:32 +00:00
|
|
|
By default your function implementation is called twice by
|
2006-09-27 03:26:52 +00:00
|
|
|
Smarty: once for the opening tag, and once for the closing tag.
|
|
|
|
(See <literal>$repeat</literal> below on how to change this.)
|
|
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
|
|
Only the opening tag of the block function may have
|
|
|
|
<link linkend="language.syntax.attributes">attributes</link>. All
|
2004-04-13 11:47:32 +00:00
|
|
|
attributes passed to template functions from the template are contained
|
2006-09-27 03:26:52 +00:00
|
|
|
in the <parameter>$params</parameter> variable as an associative array.
|
2004-04-13 11:47:32 +00:00
|
|
|
The opening tag attributes are also accessible to your function
|
|
|
|
when processing the closing tag.
|
2006-09-27 03:26:52 +00:00
|
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
|
|
The value of the <parameter>$content</parameter> variable depends on
|
2004-04-13 11:47:32 +00:00
|
|
|
whether your function is called for the opening or closing tag. In case
|
2006-09-27 03:26:52 +00:00
|
|
|
of the opening tag, it will be &null;, and in case of
|
2004-04-13 11:47:32 +00:00
|
|
|
the closing tag it will be the contents of the template block.
|
|
|
|
Note that the template block will have already been processed by
|
|
|
|
Smarty, so all you will receive is the template output, not the
|
|
|
|
template source.
|
2006-09-27 03:26:52 +00:00
|
|
|
</para></listitem>
|
2004-04-13 11:47:32 +00:00
|
|
|
|
2006-09-27 03:26:52 +00:00
|
|
|
<listitem><para>
|
|
|
|
The parameter <parameter>$repeat</parameter> is passed by
|
2004-04-13 11:47:32 +00:00
|
|
|
reference to the function implementation and provides a
|
|
|
|
possibility for it to control how many times the block is
|
|
|
|
displayed. By default <parameter>$repeat</parameter> is
|
2006-09-27 03:26:52 +00:00
|
|
|
&true; at the first call of the block-function (the opening tag)
|
|
|
|
and &false; on all subsequent calls to the block function
|
|
|
|
(the block's closing tag).
|
2004-04-13 11:47:32 +00:00
|
|
|
Each time the function implementation returns with
|
2006-09-27 03:26:52 +00:00
|
|
|
<parameter>$repeat</parameter> being &true;, the contents between
|
|
|
|
<literal>{func}...{/func}</literal> are evaluated and the function
|
|
|
|
implementation is called again with the new block contents in the parameter
|
2004-04-13 11:47:32 +00:00
|
|
|
<parameter>$content</parameter>.
|
2006-09-27 03:26:52 +00:00
|
|
|
</para></listitem>
|
|
|
|
</itemizedlist>
|
2004-04-13 11:47:32 +00:00
|
|
|
|
|
|
|
<para>
|
|
|
|
If you have nested block functions, it's possible to find out what the
|
|
|
|
parent block function is by accessing
|
2006-09-27 03:26:52 +00:00
|
|
|
<literal>$smarty->_tag_stack</literal> variable. Just do a
|
|
|
|
<ulink url="&url.php-manual;var_dump"><varname>var_dump()</varname></ulink>
|
2004-04-13 11:47:32 +00:00
|
|
|
on it and the structure should be apparent.
|
|
|
|
</para>
|
2006-09-27 03:26:52 +00:00
|
|
|
|
2004-04-13 11:47:32 +00:00
|
|
|
<example>
|
|
|
|
<title>block function</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Smarty plugin
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
* File: block.translate.php
|
|
|
|
* Type: block
|
|
|
|
* Name: translate
|
|
|
|
* Purpose: translate a block of text
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
*/
|
2004-09-07 08:27:38 +00:00
|
|
|
function smarty_block_translate($params, $content, &$smarty, &$repeat)
|
2004-04-13 11:47:32 +00:00
|
|
|
{
|
2006-09-27 03:26:52 +00:00
|
|
|
// only output on the closing tag
|
|
|
|
if(!$repeat){
|
|
|
|
if (isset($content)) {
|
|
|
|
$lang = $params['lang'];
|
|
|
|
// do some intelligent translation thing here with $content
|
|
|
|
return $translation;
|
|
|
|
}
|
2004-04-13 11:47:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
]]>
|
2004-04-14 15:53:39 +00:00
|
|
|
</programlisting>
|
2004-04-13 11:47:32 +00:00
|
|
|
</example>
|
2006-09-27 03:26:52 +00:00
|
|
|
|
|
|
|
<para>
|
|
|
|
See also:
|
|
|
|
<link linkend="api.register.block"><varname>register_block()</varname></link>,
|
|
|
|
<link linkend="api.unregister.block"><varname>unregister_block()</varname></link>.
|
|
|
|
</para>
|
|
|
|
|
2004-04-14 15:53:39 +00:00
|
|
|
</sect1>
|
|
|
|
|
2004-04-13 11:47:32 +00:00
|
|
|
<!-- 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
|
2004-04-14 15:53:39 +00:00
|
|
|
-->
|