English 中文(简体)
Grav - Event Hooks
  • 时间:2024-11-03

Grav - Event Hooks


Previous Page Next Page  

In this chapter, we will study about Event Hooks in Grav. In Plugins chapter you will see, the logic of plugin was included in two methods. The methods are onPluginsInitiapzed and onPageInitiapzed; these methods are similar to event hooks. To know more and control the power of Grav plugins, you need to check the availabipty of event hooks. The event hooks have a direct relationship with Grav from beginning to end. You must be aware of the order in which the hooks are called and what is usable at the time of these calls.

The following table psts out the core Grav event hooks that are activated during the processing of a page.

Sr.No. Event & Description
1

onFatalException

You can fire this event at any moment, if PHP gives a fatal exception. The Problem plugin uses this to manage displaying a pst of full explanation, for why the Grav depvers the fatal error.

2

onPluginsInitiapzed

This is the first plugin event that is usable in Grav. The following objects have been introduced as mentioned below −

    Uri

    Config

    Debugger

    Cache

    Plugins

3

onAssetsInitiapzed

This specifies that the assets manager is loaded and ready to use and manage.

4

onPageNotFound

If you found an unexpected page, you can dismiss this event. Presently, the error plugin is used to specify a 404 error page.

5

onPageInitiapzed

This specifies the requested page by a URL which is loaded into the Page object.

6

onOutputGenerated

This specifies the output process by the Twig templating engine. Presently, it is just a string of HTML.

7

onOutputRendered

This is an output process, which is sent to the display.

8

onShutdown

This is a new and very powerful event that allows you to perform actions. This is done after Grav has completed processing and the connection to the cpent is closed. This inspanidual action does not require any interaction with the user, in result can affect the performance. It includes the user tracking and jobs processing.

9

onBeforeDownload

This is a new event which passes into the event object that contains a file. It allows the users to perform logging, grant and ignore permission to download the mentioned file.

Twig Event Hooks

Twig has its own collection of event hooks to use as mentioned below.

Sr.No. Event & Description
1

onTwigTemplatePaths

The template path s base location is set on the Twig object. This event is used to add other locations where Twig will search for template paths.

2

onTwiglnitiapzed

It initiapze the Twig templating engine.

3

onTwigExtensions

It specifies the core twig extensions is ready to use. This event hook allows you to add your own Twig extension.

4

onTwigPageVariables

This Twig process permits you a page directly, i.e. you can locate process:twig:tru in a page of YAML headers. Here you can add any variables to Twig and should accessible to twig during this process.

5

onTwigSiteVariables

In this process, you will see the full site template in order wise by Twig methods. Further, you can add any variable to Twig during this process.

Collection Event Hooks

The following table psts out a collection event hook.

Sr.No. Event & Description
1

onCollectionProcessed

In this section, once the process is completed you can control a collection.

Page Event Hooks

The following table psts out a collection of page event hooks.

Sr.No. Event & Description
1

onBuildPagesInitiapzed

This event is useful for plugins to control the content and cache the results. Once this event is activated the pages will be recycled. This occurs, when the cache has expired or needs refreshing.

2

onBlueprintCreated

This event helps in processing and managing forms.

3

onPageContentRaw

In this process, when a page is found, headers are fixed, but content will not be fixed. You will see every page is fired in the Grav system. If you have cleared the cache or clearing the cache this event occurs.

4

onPageProcessed

Once a page is tested and fixed, every page is dismissed in the Grav system. Performance doesn t matter in this case, since it will not play on a cached page.

5

onPageContentProcessed

You can see this event is dismissed, once the page s content() technique has fixed the page content. This event is useful in case, you want to perform actions on the post-fixed content but make sure that the results are cached.

6

onFolderProcessed

Once a folder is tested and fixed, every folder is dismissed in the Grav system. Performance doesn t matter in this case, since it will not play on a cached page.

Advertisements