Edit on GitHub
Jump to docs navigation

Extending / Storage Layer / Working with Directives

Note: You are currently reading the documentation for Bolt 3.3. Looking for the documentation for Bolt 3.5 instead?

OverviewΒΆ

Directives are short segments of code that include an __invoke statement and manipulate queries. A good example of this would be the LimitDirective. As you can see the code is very simplistic and all it does is manipulates the query builder and sets a limit on the result.

The code that would execute the LimitDirective would be: {% setcontent mypages = 'pages' limit 1 %}

You can add your own directive by creating a new extension, and registering it as a directive handler for the content parser service. An example of doing that would be:

$app['query.parser'] = $app->extend(
    'query.parser',
    function ($parser) {
        return $parser->addDirectiveHandler('limit', new LimitHandler());
    }
);
Edit this page on GitHub
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on IRC.