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 -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -