LoginSignup
1
1

More than 5 years have passed since last update.

SmartyでSmarty too many shorthand attributesというエラーが出たときの原因と対処

Last updated at Posted at 2014-10-27

日本語のページがなかったので役に立つたたないはともかく残しておきます。

元々のPHPのコード自体もなかなかに複雑だったけど、省略。

Smartyのテンプレートの該当部分だけ抜粋。
エラーが出たときのコード

{$num = $items|@count}
    {if $num > 0}
        {foreach item=item from=$items}
            {section name=j start=0 loop $num - 1}
                {assign var=member value=member_|cat:$smarty.section.j.iteration}
                    // something working codes
            {/section}

            {section name=k start=2 loop $num - 1}
                 {assign var=pages value=pages|cat:$smarty.section.k.iteration}
                 // pagenatation codes
            {/section}
         {/foreach}
    {/if}

結論から言ってしまうとただのシンタックスエラーです。
原因はここ

{section name=j start=0 loop $num - 1}
{section name=k start=2 loop $num - 1}

loopに=を入れ忘れたため、startの引数としてloop, $num - 1っていうstartで期待される引数の数(1つ) を超えちゃってるよって怒られてます。

コードの重複になりますが解決編

{$num = $items|@count}
    {if $num > 0}
        {foreach item=item from=$items}
            {section name=j start=0 loop = $num - 1}
                {assign var=$member value=member_|cat:$smarty.section.j.iteration}
                    // something working codes
            {/section}

            {section name=k start=2 loop = $num - 1}
                 {assign var=$pages value=pages|cat:$smarty.section.k.iteration}
                 // pagenatation codes
            {/section}
         {/foreach}
    {/if}
1
1
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
1
1