2016-06-27 8 views
0

Smartyのdisplayメソッドは、SmartyテンプレートをHTMLに変換し、それをページに出力します。Smartyテンプレートをページに出力せずにHTMLに変換することはできますか?

SmartyテンプレートをHTMLに変換し、その内容を変数に保存する方法はありますか?

メールテンプレートをレンダリングするのにSmartyを使用したいが、明らかにそのメールをユーザーに送信する。

+0

@ AD7sixあり、私は私のページに持っている他のコンテンツだ、と私はすでに 'header'リダイレクトを処理するために出力バッファリングを使用しています。 – think123

答えて

1

そのあとで

function CompileSmartyTemplate(&$smarty,$template) { 
$compiled = ''; 
$smarty->_compile_source('evaluated template', $template, $compiled); 
ob_start(); 
$smarty->_eval('?>' . $compiled); 
$compiled = ob_get_contents(); 
ob_end_clean();  
return $compiled; 
} 

と同様にSmartyの_compile_source機能と出力バッファリングを使用して変数にそれを保存することができます

$html = CompileSmartyTemplate($smarty,$template); 
関連する問題