Grav-事件挂钩 


重力-事件挂钩


在本章中,我们将研究Grav中的Event Hooks 。在“插件”一章中,您将看到两种方法都包含了插件的逻辑。方法是onPluginsInitializedonPageInitialized ;这些方法类似于事件挂钩。若要了解更多信息并控制Grav插件的功能,您需要检查事件挂钩的可用性。事件挂钩从头到尾与Grav有直接关系。您必须了解钩子的调用顺序以及这些调用时可用的钩子。

下表列出了在处理页面期间激活的核心Grav事件挂钩

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 list of full explanation, for why the Grav delivers the fatal error.

2

onPluginsInitialized

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

onAssetsInitialized

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

onPageInitialized

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 client is closed. This individual 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拥有自己的事件挂钩集合,如下所述。

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

onTwiglnitialized

It initialize 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.

收藏活动挂钩

下表列出了收集事件挂钩。

Sr.No. Event & Description
1

onCollectionProcessed

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

页面事件挂钩

下表列出了页面事件挂钩的集合。

Sr.No. Event & Description
1

onBuildPagesInitialized

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.

0



error: 内容受到保护 !!