NotionCommotion Posted January 11, 2015 Share Posted January 11, 2015 Or should the Twig class be used to generate the content type header? require_once '../../../vendor/autoload.php'; Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem('templates'); $twig = new Twig_Environment($loader, array('debug' => true,)); $twig->addExtension(new Twig_Extension_Debug()); header('Content-type: text/html; charset=utf-8'); echo $twig->render('myTemplate.html', array()); Quote Link to comment https://forums.phpfreaks.com/topic/293852-is-a-content-type-header-required-when-using-a-twig-template/ Share on other sites More sharing options...
Jacques1 Posted January 11, 2015 Share Posted January 11, 2015 How do you want to generate the header with Twig? I'm not aware of any such feature. Personally, I define the encoding globally in the webserver configuration. Since I almost always use UTF-8, it wouldn't make sense to repeat the declaration per script. In the rare cases where I do need a different encoding, I can still override the defaults. Quote Link to comment https://forums.phpfreaks.com/topic/293852-is-a-content-type-header-required-when-using-a-twig-template/#findComment-1502579 Share on other sites More sharing options...
NotionCommotion Posted January 11, 2015 Author Share Posted January 11, 2015 You should always declare the encoding in the Content-Type header.... Your advice makes sense, however, I might have misunderstood your earlier post. I heard that I should always explicitly define the charset when setting a Content-type header. This seems contradictory to setting it globally in the webserver configuration. Quote Link to comment https://forums.phpfreaks.com/topic/293852-is-a-content-type-header-required-when-using-a-twig-template/#findComment-1502593 Share on other sites More sharing options...
Jacques1 Posted January 12, 2015 Share Posted January 12, 2015 If you declare the encoding at webserver level, that's just as explicit as emitting a Content-Type header in every single script. But the global declaration is clearly more convenient (and easier to change in case that's necessary). Where you set the encoding isn't really important. It's only important that you set it. Quote Link to comment https://forums.phpfreaks.com/topic/293852-is-a-content-type-header-required-when-using-a-twig-template/#findComment-1502607 Share on other sites More sharing options...
NotionCommotion Posted January 12, 2015 Author Share Posted January 12, 2015 Where you set the encoding isn't really important. It's only important that you set it. Just changed 80 lines of code to specify the encoding Oh well, at least Dallas and Denver lost Quote Link to comment https://forums.phpfreaks.com/topic/293852-is-a-content-type-header-required-when-using-a-twig-template/#findComment-1502611 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.