Webサイトの作成でスマーティを使うときが
たまにあるのだがテンプレートにphpを使いたい
なぁって思ってどうやるのか調べたのでメモ
{php}{/php}でphpが記述できます。
やっぱここまでくるとsmartyの変数を取得して処理をさせたく
なるんですよね。方法としては、get_template_varsを使うと
取得できます。
$this->get_template_vars('hogehoge');
おまけsmartyメモ
演算の仕方。方法は2つあります。
1. {math equation="x + y" x=2 y=1 assign=hoge}
2. {assign var=running_total value=`$hoge1+$hoge2`}
{include_php} 関数を使うと外部ファイルを
読み込ませることができます。
Smarty マニュアル {include_php}
{include_php file='hoge.php'}
smartyって結構いろいろできるんですね。
たまにあるのだがテンプレートにphpを使いたい
なぁって思ってどうやるのか調べたのでメモ

{php}{/php}でphpが記述できます。
<html>
<body>
{php}
ここにphpのコードを書く
$hoge = "smartyのテンプレートファイルにphpのスクリプト書けるよ";
$this->assign('hogehoge', $hoge);
{/php}
<p>{$hogehoge}</p>
</body>
</html>
やっぱここまでくるとsmartyの変数を取得して処理をさせたく
なるんですよね。方法としては、get_template_varsを使うと
取得できます。
$this->get_template_vars('hogehoge');
おまけsmartyメモ

演算の仕方。方法は2つあります。
1. {math equation="x + y" x=2 y=1 assign=hoge}
2. {assign var=running_total value=`$hoge1+$hoge2`}
{include_php} 関数を使うと外部ファイルを
読み込ませることができます。
Smarty マニュアル {include_php}
{include_php file='hoge.php'}
smartyって結構いろいろできるんですね。