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 php error message

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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -