2

I have a situation where sometimes a block of paragraph texts or one single image needs to be wrapped in a special div. I am trying to figure out a way to do it without having to edit the HTML which would be it as simple as 'Toggle Editor' and manually add a wrap the required tag(s).

The only way I sort of managed to achieve it was by adding the following in the Default Editor's (TinyMCE) tinymce.init function in the extended part:

style_formats : [
    {title : 'Wrapper container', block : 'div', classes : 'wrap-div', wrapper : true}
],

Now this shows a new style in the editor (Format -> Formats -> Wrapper Container) and when I apply it, it works fine but this method requires me to edit a core file and I was wondering if there was a better solution to this? Thanks.

  • I would be careful about editing the TinyMCE files. Joomla tend to update TinyMCE as much as possible so if you update your site, you could lose your changes. You may want to consider a small plugin – Lodder Mar 13 '15 at 9:16
  • 3
    You could try using JCE, it is basically a Tiny MCE extender and you can add custom styles in the profiles. – Ville Niemi Mar 13 '15 at 9:44
  • @Lodder Indeed editing TinyMCE core is something I definitely want to avoid. But I am sort of struggling with creating a plugin (for TinyMCE) that would add class to a selected div so might have to go create a editors-xtd plugin. I am trying to avoid JCE and if I understand it, I can already add custom styles in TinyMCE. What I am trying to do is to find selected text and apply a new class on the first HTML tag of the HTML element. Will see if JCE will do that still. – sifu Mar 13 '15 at 17:19
  • 1
    If you're struggling with coding, you could use NoNumbers Content Templater to do this. This will add an Editor button at the bottom and from there you can select your DIV wrappper as a template. – BodgeIT Jul 17 '15 at 8:11
1

You can use JCE, if you sign up to their membership they have JCE Template Manager which allows you to save blocks of HTML as a template.

Furthermore, you can easily add a custom editor stylesheet to JCE. Once added you simply use the dropdown to select the style.

The above comment also suggests No Numbers content Templater which I believe is more powerful although I have never used it personally many people I know recommend it. There are free & paid versions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.