PHP Twig Error: Object of class __TwigTemplate_XYZ could not be converted to string -
hey , morning :).
i'll start error message , explain afterwards i've tried , did:
catchable fatal error: object of class __twigtemplate_[64chars] not converted string in /somefolder/lib/twig/loader/filesystem.php on line 139
the full error message image:
the call stack text:
call stack # time memory function location 1 0.0001 123400 {main}( ) ../handleoop.php:0 2 0.0107 1269656 oophandler::runpage( ) ../handleoop.php:7 3 0.0107 1269768 anweisungeingeben->stepkontrolle( ) ../oophandler.php:62 4 0.0108 1271536 anweisungeingeben->ausgabe( ) ../anweisungeingeben.php:77 5 0.0383 1669484 twig_environment->render( ) ../anweisungeingeben.php:442 6 0.0383 1669484 twig_environment->loadtemplate( ) ../environment.php:347 7 0.0383 1669512 twig_environment->gettemplateclass( ) ../environment.php:378 8 0.0384 1669512 twig_loader_filesystem->getcachekey( ) ../environment.php:312
in anweisungeingeben.php
have following code fragment:
include_once "../lib/twig/autoloader.php"; twig_autoloader::register(); $template_dirs = array( $root.'templates/web/anweisungen', [...] ); $twig_loader = new twig_loader_filesystem($template_dirs); $twig = new twig_environment($twig_loader, array("debug" => true)); $template = $twig->loadtemplate('anweisung_base.phtml'); $wech = $twig->render($template); // line 442 anweisungeingeben.php
i tried:
- if paths correct (via scandir("path"))
- if twig gets loaded
minimal code like
$loader = new twig_loader_array(array('index.html' => 'hello world!')); $twig = new twig_environment($loader); echo $twig->render('index.html');
unfortunately results in same.
the strange thing is, exact same code working flawlessly in minimal project.
i know it's chaotic, project existing , growing ~20 years , twig approach try start(!) separating logic html code.
you're mixing methods up, trying pass twig_template
twig_environment
's render method, while method expect path template it's first parameter
so either :
$template = $twig->loadtemplate('anweisung_base.phtml'); echo $template->render();
or
echo $twig->render('anweisung_base.phtml');
Comments
Post a Comment