<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>register_function()</title> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Smarty Manual"> <link rel="up" href="api.functions.html" title="Chapter 13. Smarty Class Methods()"> <link rel="prev" href="api.register.compiler.function.html" title="register_compiler_function()"> <link rel="next" href="api.register.modifier.html" title="register_modifier()"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">register_function()</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="api.register.compiler.function.html">Prev</a> </td> <th width="60%" align="center">Chapter 13. Smarty Class Methods()</th> <td width="20%" align="right"> <a accesskey="n" href="api.register.modifier.html">Next</a> </td> </tr> </table> <hr> </div> <div class="refentry" title="register_function()"> <a name="api.register.function"></a><div class="titlepage"></div> <div class="refnamediv"> <h2>Name</h2> <p>register_function() — dynamically register template function plugins</p> </div> <div class="refsect1" title="Description"> <a name="id3103672"></a><h2>Description</h2> <code class="methodsynopsis"><span class="type">void </span><span class="methodname">register_function</span>(<span class="methodparam"><span class="type">string </span><span class="parameter">name</span></span>,<br> <span class="methodparam"><span class="type">mixed </span><span class="parameter">impl</span></span>,<br> <span class="methodparam"><span class="type">bool </span><span class="parameter">cacheable</span></span>,<br> <span class="methodparam"><span class="type">mixed </span><span class="parameter">cache_attrs</span></span>);</code><p> Pass in the <a class="link" href="plugins.functions.html" title="Template Functions">template function</a> name, followed by the PHP function name that implements it. </p> <p> The php-function callback <em class="parameter"><code>function</code></em> can be either: </p> <div class="itemizedlist"><ul class="itemizedlist" type="disc"> <li class="listitem"><p> A string containing the function <em class="parameter"><code>name</code></em> </p></li> <li class="listitem"><p> An array of the form <code class="literal">array(&$object, $method)</code> with <code class="literal">&$object</code> being a reference to an object and <code class="literal">$method</code> being a string containing the method-name </p></li> <li class="listitem"><p> An array of the form <code class="literal">array($class, $method)</code> with <code class="literal">$class</code> being the class name and <code class="literal">$method</code> being a method of the class. </p></li> </ul></div> <p> </p> <p> <em class="parameter"><code>cacheable</code></em> and <em class="parameter"><code>cache_attrs</code></em> can be omitted in most cases. See <a class="link" href="caching.cacheable.html" title="Controlling Cacheability of Plugins' Output">controlling cacheability of plugins output</a> on how to use them properly. </p> <div class="example"> <a name="id3104760"></a><p class="title"><b>Example 13.23. register_function()</b></p> <div class="example-contents"> <pre class="programlisting"> <?php $smarty->register_function('date_now', 'print_current_date'); function print_current_date($params, &$smarty) { if(empty($params['format'])) { $format = "%b %e, %Y"; } else { $format = $params['format']; } return strftime($format,time()); } ?> </pre> <p> And in the template </p> <pre class="programlisting"> {date_now} {* or to format differently *} {date_now format="%Y/%m/%d"} </pre> </div> </div> <br class="example-break"><p> See also <a class="link" href="api.unregister.function.html" title="unregister_function"><code class="varname">unregister_function()</code></a> and the <a class="link" href="plugins.functions.html" title="Template Functions">plugin functions</a> section. </p> </div> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="api.register.compiler.function.html">Prev</a> </td> <td width="20%" align="center"><a accesskey="u" href="api.functions.html">Up</a></td> <td width="40%" align="right"> <a accesskey="n" href="api.register.modifier.html">Next</a> </td> </tr> <tr> <td width="40%" align="left" valign="top">register_compiler_function() </td> <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td> <td width="40%" align="right" valign="top"> register_modifier()</td> </tr> </table> </div> </body> </html>