Cms: Invoking exit efter a setting content-type header reverts to text/html

Created on 29 Oct 2020  路  2Comments  路  Source: craftcms/cms

Description

When I run a template with

{% if craft.app.request.headers.get('x-request-type') == 'fetch' %}
  {% header 'Content-Type: text/plain; charset=UTF-8' %}
  {{ include('types/_' ~ entry.type) }}
  {% exit %}
{% endif %}

because I just want to render a partial (without the extra markup required for a full page), the exit call makes it ignore my explicit content-type header.

This can of course be circumvented with an else, but it doesn't seem like this was intentional, and sounds like a bug. Also cleaner to fast exit IMHO.

Steps to reproduce

  1. Set content-type with a header call.
  2. Add an exit somewhere after all content.

Additional info

  • Craft version: 3.5.9
  • PHP version: 7.4
  • Database driver & version: MariaDB 10.1
  • Plugins & versions:
bug

All 2 comments

Thanks for reporting that! Just fixed for the next release.

Holy shit, you guys are fast! I love it.

Was this page helpful?
0 / 5 - 0 ratings