Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

All plugin events available in mytheme.php?

Started by Muut Archive 12 years ago · 6 replies · 278 views
12 years ago

Docs say that we can use plugin events, are all available just as they would be for plugins?

Reason for it would be to override a setting that's in mytheme.yaml. Is there a better way of doing it besides if (!isset(page.header.width )) page.header.width = $this->config->get('width')

12 years ago

Yes you can use all plugin events in your theme's PHP file. They are like a special-case plugin.

12 years ago

That is awesome, and I'd be able to set 'form' options in YAML to have those options show in Admin when that time comes?

12 years ago

Yes, those will go in the blueprints.yaml. Any form items you define there will automatically show up in the admin.

12 years ago

That is awesome. I was working with Phile CMS which is very similar to Grav and I had to use a separate plugin to make it all work that way.

What would be the best way to have a page header override a setting set in mytheme.yaml?

12 years ago

Take a look at the SmartyPants plugin, here's a code snippet:

PHP
$defaults = (array) $this->config->get('plugins.smartypants');
$page = $event['page'];

if (isset($page->header()->smartypants)) {
    $this->config->set('plugins.smartypants', array_merge($defaults, $page->header()->smartypants));
  }

Basically does an array_merge to merge the page headers with the default configuration.

12 years ago

All events will work except for onPluginsInitialized. Instead of that you can use onThemeInitialized.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1279 9 years ago
Archive · by Muut Archive, 9 years ago
2 886 9 years ago
Archive · by Muut Archive, 9 years ago
2 4015 9 years ago
Archive · by Muut Archive, 9 years ago
1 2891 9 years ago
Archive · by Muut Archive, 9 years ago
3 1075 9 years ago