2

Long story short: I've been trying to find out how Craft processes the request and eventually create the output. The search is going deeper and deeper into the core, but it feels like I'm missing out on something.

Is it possible for a plugin to 'fetch' the (full) output of a page generated by Craft?

2
  • When you say output do you mean the generated HTML from Twig? Do you want to catch the Twig output before it sends it to the browser? Commented Oct 22, 2015 at 8:02
  • yes, but even better would be the output regardless of Twig (i.e. JSON response shouldn't go through Twig)
    – Chris
    Commented Oct 22, 2015 at 11:45

1 Answer 1

3

Craft is an MVC application, so most requests initially will get routed to a controller action. Steps 3-6 in our Routing docs page show the various ways that the target controller action is decided.

Controller actions can really do whatever they want with the request at that point, but typically they will perform some level of authorization, and then either perform an action and/or define + send the response.

For example, if you request a template path directly, the request will get routed to the templates/render action, which will verify that the template actually exists, and then render and return it, otherwise throw a 404 exception.

Template rendering is ultimately performed by TemplatesService::render(), which is where Twig gets invoked.

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.