smartyをはじめて使ったときに、あれ?ってなったところです。
Smartyのテンプレート内の処理で計算、加工をするとき
→スペースをあけると処理されない
例えば足し算引き算掛け算割り算の際に…
{assign var=”count” value=$count+1}
{assign var=”count” value=$count + 1}
スペースをあけると+がundefineですよとなる。
フォーマット加工するときも同様。
{* 今日の日付を整形 date_format を使用 *}
{$smarty.now|date_format:"%Y/%m/%d"}
{$smarty.now | date_format:"%Y/%m/%d"}
forの代わりのsectionの使い方
例 : $item_list
php > var_dump($item_list);
array(2) {
[0]=>
array(2) {
["name"]=>
string(5) "apple"
["color"]=>
string(3) "red"
}
[1]=>
array(2) {
["name"]=>
string(6) "orange"
["coler"]=>
string(6) "orange"
}
foreachの場合
{foreach from=$item_list item=$item}
{$item.name|escape}
{/foreach}
sectionの場合
■indexを指定してアクセスする場合
■index…$smarty.section.i.indexでアクセスできる
{section name=i start=0 loop=$item_list}
{assign var="count_index" value=$smarty.section.i.index}
{$item_list.$count_index.name}
{/section