Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

プリフィルタ

プリフィルタは、テンプレートがコンパイルされる前に 実行されるPHPユーザ定義関数です。テンプレートに含まれた不必要なコメントを除いたり、 第三者にテンプレートの更新を任せている時に テンプレート内にどのようなものが含まれているかを監視する等といった前処理を行います。

プリフィルタは、 登録する か、あるいは load_filter() 関数や $autoload_filters 変数によって プラグインディレクトリ から読み込みます。

Smartyは内部でユーザ定義関数の第1パラメータにテンプレートのソースコードを渡すので、 関数内で処理を行った後にその結果のソースコードを戻り値として返すようにします。

Example 15.2. プリフィルタを使用する

これはテンプレートソース内の全てのコメントを取り除いてくれるでしょう。


<?php
// このユーザ定義関数をアプリケーションに加えます
function remove_dw_comments($tpl_source, &$smarty)
{
    return preg_replace("/<!--#.*-->/U",'',$tpl_source);
}

// プリフィルタを登録します
$smarty->register_prefilter('remove_dw_comments');
$smarty->display('index.tpl');
?>

  

register_prefilter()ポストフィルタ および load_filter() も参照してください。

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 12 plus 8? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Providers @broadbandproviders.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk