craftcms / docs

Documentation for Craft CMS, Craft Commerce, and other official products.
https://craftcms.com/docs
38 stars 144 forks source link

[Content]: Note Content-Type inference for template extensions #614

Open AugustMiller opened 1 month ago

AugustMiller commented 1 month ago

Product

Craft CMS

Description

When you create a template file like my-ajax-handler.json.twig, Craft will automatically send a Content-Type: application/json header. No need for {% header ... %} tags in the template—just echo out the JSON!

This should work for any MIME type detectable via craft\helpers\FileHelper::getMimeTypeByExtension($template)—but please don't try and "render" an MP3 in Twig. :)