Please I'll like to know why twig spill out output like this: http://twig.sensiolabs.org/doc/tags/filter.html
This is what i'm working with:
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 }}
Displays <a href="/login">Login</a>
in browser
Why are the HTML tags not rendered when displayed in a browser?
Thanks for helping out.
Autoescape is probably active. You might want to tell Twig that login is a "safe" value.
{{ vars.primary_menu.login|raw }}
or
{% autoescape false %}
{{ vars.primary_menu.login }}
{% endautoescape %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With