PHP Smarty の includeテンプレートに配列を渡せない??

イシュー

  • include テンプレート側に配列を渡せないと、ブログパーツのようなものができないのだが、、

参考

includeテンプレート側に配列は渡せます

  • index.php
    • $response['test1']のvalueは配列
 $tpl = new Smarty;
 $tpl->assign("topPart01", $response['test1']);
 $tpl->display("whole.tpl");
  • whole.php
    • topPart01="$topPart01" とダブルクォートで囲んではダメ
{include file='top-part-01.tpl' topPart01=$topPart01 }
<ul>
{foreach from=$topPart01 item=foo}
    <li>{$foo.Id}</li>
{/foreach}
</ul>

Smarty のforeach内で使用できるメソッド

  • $smarty.foreach.foo.index
  • $smarty.foreach.foo.iteration
  • $smarty.foreach.foo.first
  • {$arr|@count}

参考