Forum

Thread tagged as: Question, Redactor

File link as image in Redactor

I have a client using the Redactor editor on their site. They have a number of PDF file links they want to add.

They have asked if there is a way to have an image as the link to the PDF, rather than text. Is this possible?

Many thanks

Mike

Mike Harrison

Mike Harrison 37 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It's probably doable with Redactor, but not simple. Have you considered using structured content instead?

Hi Drew, thanks for getting back to me so quickly.

That was my first response, and would be my preferred approach if starting from scratch. However they have already got a lot of content on there added through Redactor which they want to now add these image links in to.

I have found this: https://imperavi.com/redactor/docs/settings/image/#s-imagelink which sounds like the right sort of thing, though am not sure how that could be implemented in Perch. I already am using a custom config for redactor (included below) - could I add something to this to allow the functionality the client is after? I assume things are complicated somewhat by Perch Assets and the shortcodes being used.

Perch.UserConfig.redactor = function(){

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

    if (config.plugins.indexOf('perchassets') === -1) config.plugins.push('perchassets');
    if (config.plugins.indexOf('video') === -1) config.plugins.push('video');
    if (config.plugins.indexOf('widget') === -1) config.plugins.push('widget');

    if(profile == 'minimal') {
      config.plugins = [];
      config.buttons = ['html','format','bold','italic','deleted','link','lists'];
      config.formatting = ['p','blockquote'];
    }
    else if(profile == 'headings') {
      config.plugins = [];
      config.buttons = ['html','format','bold','italic','deleted','link','lists'];
      config.formatting = ['p', 'blockquote', 'h2', 'h3', 'h4'];
    }
    else {
      config.plugins = ['perchassets', 'video', 'widget'];
      config.buttons = ['html','format','bold','italic','deleted','link','lists'];
      config.formatting = ['p', 'blockquote', 'h2', 'h3', 'h4'];
    }

    return config;
  };

  var load = function(cb) {
    jQuery.getScript(Perch.path+'/addons/plugins/editors/redactor-plugins/video.js', function(){
     jQuery.getScript(Perch.path+'/addons/plugins/editors/redactor-plugins/widget.js', cb);
   });
  };



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

}();
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you could switch to using a different image plugin, but then you'd not have access to Assets. Is that a trade off you're looking to make?

Yes I would be happy with that, if that would allow me to achieve what the client needs

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, then I think you should be fine to implement that plugin.