I think I need to be using something like this (form Twig docs), but PHP says Twig_Loader_String isnt found:
$loader = new Twig_Loader_String();
$twig = \Parser\View_Twig::parser(); $twig->setLoader(new Twig_Loader_String()); $string = $twig->loadTemplate('{{ test_string }}')->render(array('test_string' => 'FuelPHP is awesome!!!')); \Debug::dump($string);
Davide Bellini wrote on Wednesday 14th of December 2011:I think I need to be using something like this (form Twig docs), but PHP says Twig_Loader_String isnt found:
$loader = new Twig_Loader_String();
Because you haven't create a Twig instance ... so use the View_Twig::parser() method to create a get this. Try to use this code :$twig = \Parser\View_Twig::parser(); $twig->setLoader(new Twig_Loader_String()); $string = $twig->loadTemplate('{{ test_string }}')->render(array('test_string' => 'FuelPHP is awesome!!!')); \Debug::dump($string);
Davide Bellini wrote on Wednesday 14th of December 2011:Please post your code ... where are you put my example? in a controller?
Have you add "parser" in config/config.php -> "always_load" => "packages" array?
$tags = array(); foreach ($params as $p) { foreach ($p as $key => $val) $tags[$key] = $val; } $twig = \Parser\View_Twig::parser(); $twig->setLoader(new Twig_Loader_String()); $string = $twig->loadTemplate( $string )->render( $tags ); return $string;
It looks like you're new here. If you want to get involved, click one of these buttons!