Get Smarty

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

Smarty の構文解析を回避する

時々、Smarty の構文解析の対象にしたくないと望む、 もしくはそうする必要がある部分があります。 典型的な例としては、 テンプレートに Javascript や CSS コードが含まれるときです。 それらの言語が Smarty のデフォルトの デリミタ である { と } を使用するときに問題が発生します。

もっとも単純な解決方法は、Javascript と CSS コードをそれぞれファイルに切り分け、 それらにアクセスするために標準的な HTML の機能を使用する事で状況を回避する事です。

リテラルコンテンツを含めるには {literal}..{/literal} ブロックを使用します。 HTML エンティティの使用法と同様に、 {ldelim}{rdelim} あるいは {$smarty.ldelim} を使用して現在のデリミタを表示することができます。

単純に Smarty の $left_delimiter および $right_delimiter を変更するだけでも便利になることが多々あります。

Example 3.8. デリミタを変更する例


<?php

$smarty->left_delimiter = '<!--{';
$smarty->right_delimiter = '}-->';

$smarty->assign('foo', 'bar');
$smarty->assign('name', 'Albert');
$smarty->display('example.tpl');

?>

  

テンプレートはこのようになります。


Welcome <!--{$name}--> to Smarty
<script language="javascript">
  var foo = <!--{$foo}-->;
  function dosomething() {
    alert("foo is " + foo);
  }
  dosomething();
</script>

  

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 2 plus 14? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk