I was unable to find anything that allowed the QuickEdit to be disabled on a per-page basis, I decided to write a quick little plugin.
The goal of the plugin is to simplify content management from the front end by allowing designers/administrators to disable the QuickEdit option on pages which do not contain content that should normally be editable, eg. pages with just snippet calls. The plugin will read a custom Template Variable to either show or hide the Quick Edit toolbar and/or content edit link.
The plugin uses Javascript to disable the QuickEdit elements, making it as unobtrusive as possible and execution order independent. The javascript is inserted just before the </body> tag, so make sure you have the tag in your template and that it’s
all lowercase.
TV Version
To install:
1) Copy and paste the below plugin code (without the beginning and ending PHP tags)
2) Select the "OnWebPagePrerender" event
3) Create a new Template Variable and associate it with your templates
- Select "DropDown List Menu" for the Input Type
- Enter "Show Editor==0||Hide Toolbar==1||Hide Edit Link==2||Hide Both==3" for Input Option Values
- Enter "0" for Default Value
<?php
/**
* @name Hide QuickEdit
* @author Brian Stanback <www.stanback.net>
*
* @license GNU General Public License
* @version 0.0.1 (01/12/07)
*
* @purpose Hides the quick editor plugin based on Template Variable
*
* @install - Copy and paste the plugin code (without the beginning and ending PHP tags)
* - Select the "OnWebPagePrerender" event
* - Create a new Template Variable and associate it with your templates
* - Select "DropDown List Menu" for the Input Type
* - Enter "Show Editor==0||Hide Toolbar==1||Hide Edit Link==2||Hide Both==3" for Input Option Values
* - Enter "0" for Default Value
*/
$tvName = "hideEditor"; // Set the name of the Template Variable
/**
* Begin plugin code
*/
// Don't do anything if we aren't logged in
if(!isset($_SESSION['mgrValidated']) || !$_SESSION['mgrValidated']) return;
$e = &$modx->Event; // Get the MODx event
// Check for the correct event
if ($e->name == 'OnWebPagePrerender')
{
// Get the current document ID or the error_document ID if document is not found
$documentIdentifier = ($modx->documentIdentifier) ? $modx->documentIdentifier : $modx->config['error_page'];
// Get the template value using API call
$hidden = $modx->getTemplateVarOutput($tvName,$documentIdentifier);
// Check the template value
if ($hidden[$tvName] > 0)
{
// JS code for hiding the quick editor
$js = "<!-- HideQuickEdit Plugin -->\n";
$js .= "<script type=\"text/javascript\">\n";
if ($hidden[$tvName] == 1 || $hidden[$tvName] == 3)
{
$js .= "document.getElementById('QE_Toolbar').style.cssText = 'height:1px;overflow:hidden;visibility:hidden;display:none;';\n";
}
if ($hidden[$tvName] > 1)
{
$js .= "// Using Prototype function\n";
$js .= "hideNodes = document.getElementsByClassName('QE_Link');\n";
$js .= "hideNodes[0].style.cssText = 'height:1px;overflow:hidden;visibility:hidden;display:none;';\n";
}
$js .= '</script>';
$o = &$modx->documentOutput; // Pass the output string by reference
// Append script to the end of the rendered html (just before body close)
$o = str_replace("</body>", "$js\n</body>", $o);
}
}
?>
Since QuickEdit’s scripts and code will still be added to the html, this plugin will not solve any namespace conflicts.
Let me know how it works, if you find it useful, or if there is some better way to achieve this.