Twig does not render HTML tags

Please, I would like to know why the spilling of conclusions is like this: http://twig.sensiolabs.org/doc/tags/filter.html

This is what I am 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 the browser

Why are HTML tags not showing when displayed in a browser?

Thanks for the help.

+3


source to share


1 answer


Autoescape is probably active. You can tell Twig that login is a "safe" value.

{{ vars.primary_menu.login|raw }}

      



or

{% autoescape false %}
    {{ vars.primary_menu.login }}
{% endautoescape %}

      

+12


source







All Articles