Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Life cycle when processing twig in a page

Started by Muut Archive 10 years ago · 2 replies · 414 views
10 years ago

Can anyone confirm the order in which events are fired when twig is processed in a page? I have a page with the following front mater:

YAML
twig_first: true
process:
    twig: true

I then try to access certain data injected by a plugin during the onPageInitialized event. But it's not available. I know the plugin is working. And a dump() in the plugin itself does indeed return the data, but it doesn't appear to be available to twig in the page (but it is if requested in a template). So what is the life cycle sequence in this case? Thanks!

10 years ago

onPageInitializedhappens about midway in the lifecycle, so you can actually add your stuff to twig in an event prior like onPagesInitialized or even onTwigInitialized to ensure they are available during page processing.

10 years ago

But the plugin needs to know the route of the page being requested. It does that using $this->grav['page']. Will that return a valid result that early? I guess I'll just have to try and see :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2956 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago