Hooks file (*.hooks.js)

The hooks file is an FCF module that exports an object with hook functions that are called at different stages of template processing.

The hooks file is created either by the SublimeFCFPlugin, VSCodeFCFFramework plugins, or by the command

$ fcfmngr create hooks [TEMPLATE_NAME]

Where:

TEMPLATE_NAME - Template name

Here is the example of the hook file for the template :templates/pages/template.tmpl

The command is also given to create the file

$ fcfmngr create hooks template

fcf.module({ name: "templates/pages/template.hooks.js", dependencies: [], module: function(){ return { // // The hook is executed before assembling the template arguments // // hookBeforeBuild: (a_taskInfo) => { // }, // // The hook is executed after assembling the template arguments // // hookAfterBuild: (a_taskInfo) => { // }, // // The hook is executed after building the template's system arguments // // hookAfterSystemBuild: (a_taskInfo) => { // }, // // The hook is called after the template is rendered // // hookAfterRender: (a_taskInfo) => { // }, // // Object of hooks for programmatically populated arguments // // hooksProgrammableArgument: { // // // // Hook of the assembly of a programmatically populated argument created by the fcf.argProg() method with the name ARG_NAME // // @result Returns the value of an argument or a Promise object // // // ARG_NAME: (a_taskInfo) => { // }, // }, // // Object of the hooks preprocessing of the template arguments // // hooksBeforeArgument: { // // // // A preprocessing hook for an argument named ARG_NAME // // // ARG_NAME: (a_taskInfo) => { // }, // // // // // This hook is called to pre-process each argument of the template // // // "*": (a_taskInfo)=>{ // }, // }, // // Object of the hooks postprocessing of the template arguments // // hooksAfterArgument: { // // // // A post-processing hook for an argument named ARG_NAME // // @result It can return an argument value or an undefined value if the argument is not redefined. // // // ARG_NAME: (a_taskInfo) => { // }, // // // // // This hook is called for post-processing of each template argument // // @result It can return an argument value or an undefined value if the argument is not redefined. // // // "*": (a_taskInfo)=>{ // }, // }, }; } });

Each hook has only one fcf.NRender.TaskInfo a_taskInfo parameter, which contains information about the progress of processing template arguments and allows you to modify the parameters of the processing and page settings. In addition, hook functions can be asynchronous.

The hooks file is well documented, so we will not pay attention to the purpose of individual hooks. Just note that hooks from the hooksProgramableArgument object are called for template arguments created with fcf.argProg().