mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-08 16:21:39 +01:00
94 lines
2.6 KiB
XML
94 lines
2.6 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 2972 Maintainer: takagi Status: ready -->
|
|
<!-- CREDITS: mat-sh,daichi,joe -->
|
|
<refentry id="api.register.function">
|
|
<refnamediv>
|
|
<refname>register_function()</refname>
|
|
<refpurpose>テンプレート関数プラグインを動的に登録します。</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>説明</title>
|
|
<methodsynopsis>
|
|
<type>void</type><methodname>register_function</methodname>
|
|
<methodparam><type>string</type><parameter>name</parameter></methodparam>
|
|
<methodparam><type>mixed</type><parameter>impl</parameter></methodparam>
|
|
<methodparam choice="opt"><type>bool</type><parameter>cacheable</parameter></methodparam>
|
|
<methodparam choice="opt"><type>mixed</type><parameter>cache_attrs</parameter>
|
|
</methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
パラメータには、<link linkend="plugins.functions">テンプレート関数</link>
|
|
名とそれを実装する PHP のユーザー定義関数名を渡します。
|
|
</para>
|
|
&api.register.snippet;
|
|
|
|
|
|
<para>
|
|
<parameter>cacheable</parameter> と <parameter>cache_attrs</parameter> は、
|
|
ほとんどの場合に省略可能です。これらの正しい使用法についての詳細は、
|
|
<link linkend="caching.cacheable">キャッシュ可能なプラグインの出力の制御</link>
|
|
を参照して下さい。
|
|
</para>
|
|
<example>
|
|
<title>register_function()</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?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());
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
テンプレート
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{date_now}
|
|
|
|
{* 異なるフォーマット *}
|
|
{date_now format="%Y/%m/%d"}
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<para>
|
|
<link linkend="api.unregister.function"><varname>unregister_function()</varname></link>
|
|
および
|
|
<link linkend="plugins.functions">テンプレート関数プラグイン</link> の項も参照してください。
|
|
</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
|
|
-->
|
|
|