2012-03-02 5 views
0

json配列のSmartyテンプレートを返す方法は?例えば

PHP:json配列のsmartyテンプレートを返す

$smarty=new Smarty(); 
.... 
$title='some text'; 
echo json_encode(array('title'=>$title,'page'=>$smarty->display('templatename.tpl'))); 

のjQuery:

$.post('pages.php',{id:id,page:page},function(json){ 
    $('.title').text(json.title); 
    $('.content').html(json.page); 
},'json'); 

答えて

1

のSmartyのdisplay()エコーoutbutバッファにレンダリングされたテンプレート。レンダリングされたテンプレートを文字列として取得するには、おそらくfetch()が必要です。

<?php 
// … 
header('Content-Type: application/javascript'); 
echo json_encode(array(
    'title' => $title, 
    'page' => $smarty->fetch('templatename.tpl'), 
)); 
+0

ありがとう、私は試してみます。 :) – Eugene

関連する問題