Mecha CMS

Updates.

Filter Hook’s Stack Orders

Author: Taufik Nurrohman · 88 Views

Tweet

Just some notes.

Table of Content

I’m started to think that it is important to standardize the hook stack order to make sure that everything can be executed in the proper order. These tables will help you to set your own filter stack properly and to make sure that your custom filters will run before or after these filters.

For example, to create a filter that will be used to replace raw Markdown syntax, you have to set the $stack value to be less than 2 because fn_markdown runs in level 2; to create a filter that will be used to replace HTML code or HTML version of Markdown, you have to set the $stack value to be greater than 2, so that your filter will run after fn_markdown.

Related: Class Hook

Hooks 

Shield 

StackHookToSource
0fn_assetshield.outputAsset
1fn_artshield.outputArt Direction
2fn_minifyshield.outputMinify

Page 

StackHookToSource
0fn_block_x*.contentBlock
.9fn_block_e*.contentBlock: Eval
1fn_block*.contentBlock
1.9fn_markdown_link*.content, *.descriptionMarkdown Smart Internal Links
2fn_markdown*.description, *.contentMarkdown
2fn_markdown_span*.titleMarkdown
3fn_rapicpage.contentRAPIC – Random Ad Position in Content
fn_block:110fn_block_url*.contentBlock: URL
fn_block:110fn_archivepage.contentArchive
fn_block:110fn_tocpage.contentTable of Content

Examples 

Add support for <mark> syntax in Markdown with ‌=‌=‌text‌=‌=‌:

Hook::set('page.content', function($content, $lot) {
    if (!isset($lot['type']) || $lot['type'] !== 'Markdown') {
        return $content;
    }
    if (strpos($content, '==') === false) {
        return $content;
    }
    return preg_replace('#\b‌=‌=‌([^=]+?)‌=‌=‌\b#', '<mark>$1</mark>', $content);
}, 1.9);

0000000000

0 Comments

No comments yet.