Files
smarty/docs/en/programmers/api-functions/api-register-block.xml
2006-09-26 23:29:02 +00:00

91 lines
2.5 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<refentry id="api.register.block">
<refnamediv>
<refname>register_block()</refname>
<refpurpose>dynamically register block functions plugins</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>void</type><methodname>register_block</methodname>
<methodparam><type>string</type><parameter>name</parameter></methodparam>
<methodparam><type>mixed</type><parameter>impl</parameter></methodparam>
<methodparam><type>bool</type><parameter>cacheable</parameter></methodparam>
<methodparam><type>mixed</type><parameter>cache_attrs</parameter></methodparam>
</methodsynopsis>
<para>
Use this to dynamically register
<link linkend="plugins.block.functions">block function plugins</link>.
Pass in the block function <parameter>name</parameter>, followed by the PHP
function's name that implements it.
</para>
&api.register.snippet;
<para>
<parameter>cacheable</parameter> and <parameter>cache_attrs</parameter>
can be omitted in most cases. See <link
linkend="caching.cacheable">controlling cacheability of plugins' output</link>
section on how to implement them properly.
</para>
<example>
<title>register_block()</title>
<programlisting role="php">
<![CDATA[
<?php
// function declaration
function do_translation ($params, $content, &$smarty, &$repeat)
{
if (isset($content)) {
$lang = $params['lang'];
// do some translation with $content
return $translation;
}
}
// register with smarty
$smarty->register_block('translate', 'do_translation');
?>
]]>
</programlisting>
<para>
Where the template is:
</para>
<programlisting>
<![CDATA[
{translate lang='br'}Hello, world!{/translate}
]]>
</programlisting>
</example>
<para>
See also
<link linkend="api.unregister.block"><varname>unregister_block()</varname></link>
and the
<link linkend="plugins.block.functions">plugin block functions</link> page.
</para>
</refsect1>
</refentry>
<!-- 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
-->