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

Surahman
Surahman

I need to make a global object in a plugin. I mean, when the plugin has installed, let say the plugin have setting object. Which mean, I can access the object in the page with {{ this.setting.property }} or maybe the simple one {{ setting.property }}. I know we can create a component and make the variable. But, I need it without any component such as in this doc.

Thanks.

Last updated

triasrahman
triasrahman

Hey master,

Maybe this solution can help you:

    public function boot()
    {
        // Global variable for settings
        Event::listen('cms.page.beforeDisplay', function($controller, $url, $page) {
            $controller->vars['settings'] = SettingsModel::instance();
        });
    }

Add this event listener to your boot() method at Plugin.php. And then add your custom variable on CmsController. OctoberCMS made it easy!

Last updated

Surahman
Surahman

Wow, thank you. It works!

You save my day.

1-3 of 3

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