HTML does not display [Twig] / [Slim]

I use the branch as a template engine, but my html is not rendering. Everything is displayed with the HTML tags themselves.

Data from the database can be found by clicking here.

I searched for SO and got a lot of posts that provide a solution, but no one worked for me

Following are the solutions:

  • Use below code [ doesn't work ]

    {{ detailArticle.artdesc|raw }}
    
     or
    
    {% autoescape false %}
      {{ detailArticle.artdesc }}
    {% endautoescape %}
    
  • Use filter and autoload as shown below [ doesn't work ]

    $app->view = new \Slim\Views\Twig();
    $app->view->setTemplatesDirectory("application/view");
    $app->view->parserOptions = array(
       'debug' => 'true',
       'auto_reload' => true,
       'autoescape' => true
    );
    $app->view->parserExtensions = array(new \Slim\Views\TwigExtension());
    
  • Clear Twig cache [ I don't have a CLI in cPanel, so I'm not sure how to do this )

    rm -rf app/cache/*  OR rm -rf app/cache/prod/twig OR app/console cache:clear --env=prod
    

None of the solutions working for me. Please guide.

Data is displayed in the same way as you will see on the link mentioned above.

My composer .json as below

{
 "name":"panique/mini2",
 "homepage":"https://github.com/panique/mini2",
 "license":"MIT",
 "require":{
    "php":">=5.3.0",
    "slim/slim": "~2.6",
    "slim/views": "~0.1",
    "twig/twig": "~1.16",
    "panique/pdo-debug": "0.2",
    "panique/php-sass": "~1.0",
    "matthiasmullie/minify": "~1.3"
 },
"autoload":{
    "psr-4":{
        "Mini\\": "Mini"
    }
 }
}
+4
2

. php:

$escaper = new Twig_Extension_Escaper(false);
$app->view->addExtension($escaper);

require_once 'path_to_Twig/Autoloader.php';
Twig_Autoloader::register();

$loader = new Twig_Loader_Filesystem('path_to_views/');
$twig = new Twig_Environment($loader, array());

$escaper = new Twig_Extension_Escaper(false);
$twig->addExtension($escaper);

echo $twig->render($view_name, $data_to_view);

 require 'vendor/autoload.php'; 

 // Initialize Slim (the router/micro framework used) 
 $app = new \Slim\Slim(array( 
 'mode' => 'production' 
 )); 

 require_once 'path_to_Twig/Autoloader.php'; //Substitute the Twig path, the path to the uncompress files in the project 
 Twig_Autoloader::register(); 

 $loader = new Twig_Loader_Filesystem('path_to_views/'); //Substitute with the path with the html files 
 $twig = new Twig_Environment($loader, array()); 

 $escaper = new Twig_Extension_Escaper(false); 
 $twig->addExtension($escaper); 

 echo $twig->render($view_name, $data_to_view); //First the name of the view html file, data that you want pass to the view in one array 

, , .

+2

, Twig_Extnesion_Escaper:

$v = new \Slim\Views\Twig(__DIR__ . '/../../templates', [
    'cache' => __DIR__ . '/../../templates/twigcache'
]);
$v->addExtension(new Twig_Extension_Escaper());
0

All Articles