Forum

Thread tagged as: Addons, Redactor

Adding "View Source" to the built-in Redactor 2 Editor in Perch 3

This forum is littered with threads on how to do this and they're all dead ends. I just wanted to share the way I did it so it can maybe help someone else. Credit to Clive Walker as this is pretty much what he describes in a few places like here and here, but with a bit more detail and updated links and code.

Step 1 - Download the plugin

This step is the one we all get hung up on, because Redactor updated to v3 and there no longer is a source plugin on their website. However the plugin still exists online at github, and you can download the source.js file here: https://github.com/Redactor2/plugins

Step 2 - Save it

Save the file to: /addons/plugins/editors/redactor-plugins/source.js

Step 3 - Update Your Config File

Basically follow instructions from the heading "Custom Configurations for Default Editors" here: https://docs.grabaperch.com/api/editors/ adding this to your /config/config.php file

define('PERCH_CUSTOM_EDITOR_CONFIGS', true);

Step 4 - Create a config.js file in the editors folder

Continuing with the instructions from the link in step 3, create a file at /addons/plugins/editors/config.js with the following content.
(Note that the below is modified to only include the source plugin, and not the font color plugin that is also included in the linked instructions)

Perch.UserConfig.redactor = function(){

  var get = function(profile, config, field) {

    if (config.plugins.indexOf('source') === -1) config.plugins.push('source');

    return config;
  };

  var load = function(cb) {
    if (typeof jQuery.Redactor.prototype.source == 'undefined') {
        jQuery.getScript(Perch.path+'/addons/plugins/editors/redactor-plugins/source.js', cb);    
    } else {
      cb();
    }
  };

  return  {
    'get': get,
    'load': load
  }

}();

Step 5 - Celebrate

Go test your redactor editor and marvel in amazement at your new HTML button. Then use it to clean up or modify your HTML content when necessary.

Dominic Tocci

Dominic Tocci 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Thanks Dominic.