Twig 不呈现 HTML 标签 [英] Twig doesn't render HTML tags
本文介绍了Twig 不呈现 HTML 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请我想知道为什么 twig 会输出这样的输出:http://twig.sensiolabs.org/doc/tags/filter.html
Please I'll like to know why twig spill out output like this: http://twig.sensiolabs.org/doc/tags/filter.html
这就是我正在使用的:
class MyClass {
public function loadViewWithContent($name, $variables) {
$twig = load_twig();
// look at the pages dir
$page = getdir("pages") . $name . '.html';
$variables['vars'] = $this->menuItem();
if(file_exists($page)) {
print $twig->render($name . '.html', $variables);
}
}
public function menuItem() {
$loginmenu = array(
'text' => 'Login',
'path' => '/login',
'attributes' => array(
'target' => '',
'title' => 'Login'
)
);
$menus = array(
'primary_menu' => array(
'login' => $this->theme_link($loginmenu),
),
);
return $menus;
}
public function theme_link($menu) {
if(is_array($menu)) {
$output = '<a href="' . $menu['path'] . '">' . $menu['text'] . '</a>';
}
return $output;
}
}
$clazz = new MyClass();
$clazz->loadViewWithContent('home', array());
home.html
{{ vars.primary_menu.login }}
在浏览器中显示Login
Displays <a href="/login">Login</a>
in browser
为什么 HTML 标签在浏览器中显示时没有呈现?
Why are the HTML tags not rendered when displayed in a browser?
感谢您的帮助.
推荐答案
Autoescape 可能是活跃的.您可能想告诉 Twig 登录是一个安全"值.
Autoescape is probably active. You might want to tell Twig that login is a "safe" value.
{{ vars.primary_menu.login|raw }}
或
{% autoescape false %}
{{ vars.primary_menu.login }}
{% endautoescape %}
这篇关于Twig 不呈现 HTML 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文