1

I'm working on a Content Security Policy and need to set an HTTP header after all templates have finished processing. Right now I'm doing that by calling a module variable at the bottom of the main layout template, but that feels brittle.

Is there an Event that can be used for this? I've looked through craft\events in the API docs but don't see a good candidate.

1
  • Ah! Maybe EVENT_AFTER_RENDER_PAGE_TEMPLATE? Does "page template" equate to the layout that's being extended?
    – plaintxt
    Sep 23, 2022 at 16:28

1 Answer 1

1

Yahtzee.

use craft\web\View;
use yii\base\Event;

...

Event::on(View::class, View::EVENT_AFTER_RENDER_PAGE_TEMPLATE, function (Event $event) {
    // do things
});

https://docs.craftcms.com/api/v3/craft-web-view.html#event-after-render-page-template

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.