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.

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

1 Answer 1



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


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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