Disabling for new resources

I need to turn CB off for the blog on a site. I have a plugin firing OnDocFormPreRender as below but new resources still have CB enabled. What am I doing wrong?!

<?php $eventName = $modx->event->name; switch($eventName) { case 'OnDocFormPrerender': $resource = $modx->controller->resource; $disabled = false; $disabledTemplates = array(7); if (in_array($resource->get('template'), $disabledTemplates)) { $disabled = true; } if ($disabled) { $resource->setProperty('_isContentBlocks', false, 'contentblocks'); } $modx->log(modX::LOG_LEVEL_ERROR, $disabled); break; }

Hi Chris, I’ve got the same problem. Did you find a solution?

I’m afraid not, no :frowning:

As I needed a solution fast, I temporarily hacked the ContentBlocks plugin. But that was a bad idea

I’ve also asked the Modmore team for support, they’ll probably have a better solution than this, but for now, it works.

Just for the record, I very strongly recommend you to not touch the ContentBlocks plugin.

This is the recommended approach. https://support.modmore.com/faq/8-contentblocks/#faq_72

Make sure the right plugin event is checked and that your cache is cleared. If all that’s set up, it could be the priority. If your plugin executes after the ContentBlocks one, it wont work. This is also mentioned in that FAQ entry:

Note: this only works if the ContentBlocks plugin has a higher priority number on the OnDocFormPrerender event than your own plugin. You can quickly edit this by right clicking the system event, choosing Update Plugin Event, and double clicking in the Priority column.

I agree with you completely and I know I shouldn’t hack the plugin, and I also just realized what I did wrong.

With ‘higher priority’, I was thinking a LOWER number (the lower the number, the higher the priority, right?). But I think it’s the other way around.
So Contenblocks priority=1, and my plugin priority=0.
The wording confused me I guess.

No hack needed anymore :smiley:

1 Like

Hi Mark / Chris

The plugin works great for existing resources. However, I get an error when trying to create a new resource.

This is because $resource->get(‘template’) is not available, before the plugin fires.

Do you guys experience the same? Or more importantly, have you found a work-around?

I have the same issue - I need CB to be turned off for new resources in a section of a site. I haven’t found a work-around yet

1 Like

YJ’s plugin solution https://www.sepiariver.ca/blog/modx-web/contentblocks-restricted-by-template/ does not throw up an error when creating a new resource. However, I also want new resources (that do not have a specific template) to set CB to disabled.

Thanks folks, I’ve updated the sample code at https://support.modmore.com/faq/8-contentblocks/#faq_73 to also work on new resources.