簡體   English   中英

Twig不輸出編譯的模板,僅回顯模板文件名

[英]Twig doesn't output compiled template, just echoes template filename

我在Wordpress環境,PHP 5.4.1和Apache中。 以下是在我的functions.php中:

require_once( get_template_directory() . '/libs/twig/lib/Twig/Autoloader.php' );
Twig_Autoloader::register();
$loader = new Twig_Loader_String( get_template_directory().'/partials/twig-templates' );
$Twig = new Twig_Environment($loader);

//doesn't work, outputs "test.html" in plain text
echo $Twig->render('test.html', array('name' => 'Cameron')); 

//this does output a compiled template, "hey Cameron"
echo $Twig->render('hey {{name}}', array('name' => 'Cameron'));

我已驗證Twig是否已正確加載,並且模板的文件路徑正確。

我猜它忽略了一些簡單的事情。 有什么想法嗎? 謝謝!

您的加載器是Twig_Loader_String,只能與字符串輸入一起使用。

對於要渲染的文件,請使用

$loader = new Twig_Loader_Filesystem('/path/to/templates');

http://twig.sensiolabs.org/doc/intro.html

暫無
暫無

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

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