Why rendering view shows HTML tags?


#1

Hello,

I’ve added Slim Twig Framework to my PHP project.
I’ve configured the route of the templates etc:

Twig::class => function (ContainerInterface $container) {

    $view = new Twig(
        $container->get('settings.template_path'),
        [
            'debug' => $container->get('settings.debug'),
        ]
    );

    $view->addExtension(new TwigExtension(
        $container->get('router'),
        $container->get('request')->getUri()
    ));

    return $view;
},

And while trying to render the view in one of the Controllers:

    return $this->view->render(
        $response,
        'login.html.twig'
    );

I receive in the browser just the HTML code (without twig tags though):

    <!DOCTYPE html>
    <html>
      <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
     ...

Why is it happening? Is it something about the configuration?
Sorry if the topic exists already, but through the searcher I haven’t found anything about it…


#2

How did you configure your web server? In the response headers what does it show as the content-type?


#3

I have nginx with other projects working there already.
The configuration of the project is:

server {
    listen 80;
    server_name abc-development.abc.com;
    root "/var/www/abc/current/public";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
    #auth_basic "Restricted Content";
    #auth_basic_user_file /etc/nginx/.htpasswd;

    if (!-e $request_filename) {
        rewrite /(.*)/favicon\.ico$ /favicon.ico last;
        rewrite /(.+)/(css|js|images|fonts)/(.+)$ /$2/$3 last;
        rewrite ^/(.*)$ /index.php last;
        break;
    }
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

access_log off;
error_log  /var/log/nginx/abc-error.log error;

sendfile off;

client_max_body_size 100m;

location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php5.6-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

    location ~ /\.ht {
        deny all;
    }
}

I was changing the Content-type of the response to ‘html/text’ and still the result was the same…


#4

I’m not familiar with nginx so I can’t help there, but the content type should automatically be text/html (not html/text). But you shouldn’t need to set that which is why I’m thinking it is something with your webserver config. (But again, I don’t know much about nginx.)