2013-03-20 79 views
1

使用$ smarty-> fetch時,它將模板拉入變量。有沒有辦法對該變量進行預解析的字符串操作?smarty取取字符串替換

例子:

PHP:

$variable = $smarty->fetch('template.tpl'); 
$variable = str_replace("{include file='../another_dir", "{include file='", $variable); 

template.tpl

{include file='incl.tpl'} 

理想的結果將是有模板變成:

{include file='../another_dir/incl.tpl'} 

回答

2

你必須編輯模板第一。然後你可以使用fetch。

事情是這樣的:

$template = file_get_contents('template.tpl'); 
$template = str_replace("{include file='../another_dir", "{include file='", $template); 
$variable = $smarty->fetch('string:' . $template); 

Smarty的String Template Resources