This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

geoff.beaumont
geoff.beaumont

OctoberCMS has a convenient way of loading twig filters and functions in a plugin: http://octobercms.com/docs/plugin/registration#extending-twig

However, it looks like this only registers them for use in front end theme views - if the plugin (or any other plugin) also provides components, the filters and functions are not available in the component partial views.

For instance, I have the following code in a plugin class (yes, the classpath has been anonymised):

public function registerMarkupTags()
{
    return [
        'filters' => [
            'jsonlist' => ['My\Plugin\Classes\TwigExtensions', 'jsonList']
        ]
    ];
}

This filter works fine if I put in a theme view, but if I try to use it in a component I get an undefined constant exception. The same goes if I try to use a filter from another plugin (e.g. the 'staticPage' filter from RainLab Pages).

How do I get my plugin to load the filter properly so that it is available to component twig views not just theme views?

geoff.beaumont
geoff.beaumont

Okay, red herring - though I still have an issue. The partial attempting to use the filter wasn't actually a component one (I've tested that, and got it working). It's actually a partial referenced from a form definition. I'm rendering backend forms in the front end, but the error appears the same in the backend when viewing the same form. So, looks like I need to figure out how to register the filter with the backend renderer as well.

geoff.beaumont
geoff.beaumont

And...I'm a complete idiot :(

Form partials are plain PHP not twig. I'm going to stand in the corner with the dunce hat on...

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.