You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to only active the comments function when to active flag in the frontmatter is set. This is not yet implemented and I think this might not be possible at all. It would be nice, if you could give me some hints:
onPluginsInitialized Event will check if the route is set in the config and enables the plugin
onFormPageHeaderProcessed Adds the form to the page header
onPageInitialized Gives us the page object along with its header settings
The problem is, that I must check if the plugin should be enabled in step 3. But I cannot add the form from step 1 at this late step. This means I can only enable/disable the comments plugin from uris?
Enabling the plugin on a per-page basis has multiple usecases:
You dont need to edit the plugin config every time, just the page
You do not need to use uris, which might change
You can also enable comments for a special page template, e.g. only for blog posts, no matter at which route they are
This plugin will only be active, where is should. currently you can send a POST to a page without comments form and a comment will be silently added to the data directory
Is there a way to add a form to the page header at a later time?
The text was updated successfully, but these errors were encountered:
I've found a solution that works inside the onPageInitialized event:
publicfunctiononPageInitialized(Event$event)
{
// Check if the plugin should be enabled.// We need to check this in the page initialized event// in order to access the page template property.$this->calculateEnable();
// Enable the main events we are interested inif ($this->enable) {
// NOTE: We must add the form here and not in the onFormPageHeaderProcessed event.// The mentioned event will run before onPageInitialized, but we can only validate// the page template filters after the page got initialized. Thatswhy the form will be// added at this later stage.$page->addForms([$this->grav['config']->get('plugins.comments.form')]);
$this->enable([
'onFormValidationProcessed' => ['onFormValidationProcessed', 0],
'onFormProcessed' => ['onFormProcessed', 0],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
]);
}
}
If this functionality is also desired for the comments plugin I am happy to create a PR.
I am trying to only active the comments function when to
active
flag in the frontmatter is set. This is not yet implemented and I think this might not be possible at all. It would be nice, if you could give me some hints:The problem is, that I must check if the plugin should be enabled in step 3. But I cannot add the form from step 1 at this late step. This means I can only enable/disable the comments plugin from uris?
Enabling the plugin on a per-page basis has multiple usecases:
Is there a way to add a form to the page header at a later time?
The text was updated successfully, but these errors were encountered: