php - My Twig template's parameters are ignored -


i'm using standalone twig instance in custom application, parameters (context) passed template seem surprisingly ignored.

executing following code results in error :

fatal error: uncaught exception 'twig_error_runtime' message 'variable " msg" not exist in "hello.twig" (...)

test.php

$options = array(       'charset' => 'utf-8',       'debug' => true,       'strict_variables' => true, );  $env = new twig_environment(new \twig_loader_filesystem(getcwd()), $options);  return $env->render("hello.twig", array('msg' => 'world')); // tried return $env->loadtemplate("hello.twig")->render(array('msg' => 'world')); 

hello.twig

hello {{ msg }} 

registering global variable ( $env->addglobal('msg', 'everybody') ) no more successful.

did miss or should working?

as elefantphace pointed out, unsecable space present after {{ in twig template, resulting in wrong variable name. replacing regular space character solved problem :)


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -