簡體   English   中英

Smarty:有沒有辦法檢測是否所有預期變量都已傳遞到模板?

[英]Smarty: Is there a way to detect whether all expected variables were passed to the template?

假設我有一個包含以下內容的模板文件:

<div>
        var 1: {$var1}<br>
        var 2: {$var2}
</div>

我做了以下分配,而忘記分配var2:

$smarty->assign("var1", "foo");
$smarty->display($tpl_file);

檢測未分配所有必需變量的最佳方法是什么?

謝謝。

Smarty本身沒有這樣的功能,您可以嘗試編寫自己的東西:

preg_match_all('/{\$(.*?)}/', file_get_contents('templates/index.tpl'), $vars, 2);

foreach ($vars as $v)
{
    echo $v[1]."<br>";
}

從此處獲取: http ://smarty.incutio.com/?page=SmartyFrequentlyAskedQuestions# project-10

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM