How can ContentBlocks be DISABLED on specific templates?

In ContentBlocks v1.10 and up, you can configure ContentBlocks to be enabled or disabled on specific templates by adding a template property.

Start by making sure ContentBlocks is enabled globally. That's done with the contentblocks.disabled system setting, which should be set to 0 or an empty value. Alternatively, this can also be set on the context wit a context setting with that same key and value.

Next you can add a property to the templates you want to disable. That property has the same key as the settings (contentblocks.disabled) and should be set to 1 on the template(s) you wish to disable ContentBlocks for. The template property has priority over system and context settings. 

Detailed instructions for the template property can be found in the documentation.

Older versions (v1.9 and earlier)

ContentBlocks v1.9 and earlier do not support the template properties. To blacklist templates in those releases, create a new plugin with the following contents:

<?php 
$eventName = $modx->event->name;
switch($eventName) {
     case 'OnDocFormPrerender':
         $resource = $modx->controller->resource;
         $disabled = false;
         $disabledTemplates = [1, 3, 5];
         if ($resource && in_array($resource->get('template'), $disabledTemplates)) {
             $disabled = true;
         }
         if ($disabled) {
             $resource->setProperty('_isContentBlocks', false, 'contentblocks');
         }
         break;
}

On the System Events tab, enable the  OnDocFormPrerender event.

In this example plugin, ContentBlocks is turned off for template 1, 3 or 5, which you'll want to change for your use case. Please note that this will overwrite the "Use ContentBlocks" setting on resources with those templates.

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.

Still need help? Send us an email Send us an email