2007-04-21 12:13:34 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
|
<!-- $Revision$ -->
|
2009-06-14 07:23:39 +00:00
|
|
|
<!-- EN-Revision: 2972 Maintainer: takagi Status: ready -->
|
2007-04-21 12:13:34 +00:00
|
|
|
<!-- CREDITS: mat-sh,daichi,joe -->
|
|
|
|
|
<sect1 id="plugins.compiler.functions"><title>コンパイラ関数プラグイン</title>
|
|
|
|
|
<para>
|
|
|
|
|
コンパイラ関数プラグインはテンプレートのコンパイル時にのみ呼び出されます。
|
|
|
|
|
これらのプラグインは、PHPコードまたは時間に依存する静的コンテンツをテンプレートに含める時に便利です。
|
|
|
|
|
コンパイラ関数と <link linkend="language.custom.functions">カスタム関数</link>
|
|
|
|
|
が双方とも同じ名前で登録された場合は、コンパイラ関数が優先されます。
|
|
|
|
|
</para>
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>mixed <function>smarty_compiler_<replaceable>name</replaceable></function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>$tag_arg</parameter></paramdef>
|
|
|
|
|
<paramdef>object <parameter>&$smarty</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
コンパイラ関数には2つのパラメータを渡します。
|
|
|
|
|
これらのパラメータは、タグ内の文字列(基本的に関数名から終端デリミタまでの全ての文字列)と、
|
|
|
|
|
Smartyのオブジェクトです。戻り値には、コンパイルされたテンプレートに挿入されるPHPコードを返します。
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
<example>
|
|
|
|
|
<title>シンプルなコンパイラ関数プラグイン</title>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
* Smarty plugin
|
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
|
* File: compiler.tplheader.php
|
|
|
|
|
* Type: compiler
|
|
|
|
|
* Name: tplheader
|
|
|
|
|
* Purpose: ソースファイル名とそれがコンパイルされた時間を含む
|
|
|
|
|
* ヘッダを出力する
|
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
function smarty_compiler_tplheader($tag_arg, &$smarty)
|
|
|
|
|
{
|
|
|
|
|
return "\necho '" . $smarty->_current_file . " compiled at " . date('Y-m-d H:M'). "';";
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
<para>
|
|
|
|
|
この関数はテンプレートから次のように呼ばれます。
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
|
|
|
|
<![CDATA[
|
|
|
|
|
{* この関数はコンパイル時にのみ呼び出されます *}
|
|
|
|
|
{tplheader}
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
<para>
|
|
|
|
|
コンパイルされたテンプレートの結果として生じるPHPコードは次のようになります。
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
|
|
|
|
echo 'index.tpl compiled at 2002-02-20 20:02';
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
|
|
|
|
|
<para>
|
|
|
|
|
<link linkend="api.register.compiler.function">
|
|
|
|
|
<varname>register_compiler_function()</varname></link>
|
|
|
|
|
および
|
|
|
|
|
<link linkend="api.unregister.compiler.function">
|
|
|
|
|
<varname>unregister_compiler_function()</varname></link>
|
|
|
|
|
も参照してください。
|
|
|
|
|
</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
|
|
|
|
|
-->
|