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()); 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. 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 On 1/11/2015 at 5:58 PM, Jacques1 said: 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. 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. 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 On 1/12/2015 at 1:19 AM, Jacques1 said: 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 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
Archived
This topic is now archived and is closed to further replies.