静的文字列をキャプチャする場合の Smarty バージョン 2:
{capture name=test}
a huge page or string can go here
{/capture}
{$smarty.capture.test} を使用して、キャプチャした文字列を現在のテンプレートまたは子テンプレートの両方に問題なくダンプできます。
次のような「{foreach}」ループをキャプチャしようとすると:
{capture name=test}
{foreach item=Row from=$DataGrid.Rows name=RowsGrid}
,['{$Row.DataCells.project_name.Data}', {$Row.DataCells.approved_budget.Data}]
{/foreach}
{/capture}
次のように、現在のテンプレートで簡単に使用できます。
{$smarty.capture.test}
正しいデータを文字列として表示します。ただし、子テンプレートで使用しようとすると:
{include file='/full/path/child.tpl'}
{$smarty.capture.test}
次のような空のキャプチャされたデータになります。
,['', ] ,['', ] ,['', ]
{$smarty.capture.test|var_dump} を使用すると、「string(86)」と表示されます。何が欠けていますか?