5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

smartyで最初につまづいたところ

Last updated at Posted at 2016-12-28

smartyをはじめて使ったときに、あれ?:confused:ってなったところです。

:purple_heart: Smartyのテンプレート内の処理で計算、加工をするとき

→スペースをあけると処理されない

例えば足し算引き算掛け算割り算の際に…
:o:{assign var=”count” value=$count+1}
:x:{assign var=”count” value=$count + 1}
スペースをあけると+がundefineですよとなる。

フォーマット加工するときも同様。
{* 今日の日付を整形 date_format を使用 *}
:o:{$smarty.now|date_format:"%Y/%m/%d"}
:x:{$smarty.now | date_format:"%Y/%m/%d"}

:blue_heart: 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
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?