On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I’ve been working on a few sites which have very different templates for different sections. One of the things I’ve really missed with tinymce is that I couldn’t show those very different styles in the editor. That is until now... Admittedly it’s a bit of a crude hack but not too difficult.

    1. I have a general editor style sheet: assets/site/tinymce.css which is set in the site configuration. Next to that I’ve created style sheets for each template where I want to divert from the default. I’ve named these template1.css, template2.css etcetera. The number is the id of each template.

    2. I made 3 changes in the TinyMCE plugin code.
    Firstly it needs access to the global $content variable.
    // Handle event
    global $content; //mod by JJC
    $e = &$modx->Event; 

    Then a test to see if an editor css file exists in the onRichTextEditorInit event and replace the occurence of $modx->config[’editor_css_path’] in both the getTinyMCEScript() calls with the $tiny_mce_path variable created earlier.
        case "OnRichTextEditorInit": 
        //check if template has it's own editor css file
        $tiny_css_path = $modx->config['editor_css_path']; //set default css file
        $template_css = 'assets/site/template'.$content['template'].'.css';
        if( file_exists($modx->config['base_path'] . $template_css) ) 
          $tiny_css_path = $modx->config['base_url'].$template_css;
        if($editor=="TinyMCE") {
          $elementList = implode(",", $elements);
            $frontend = 'true';
            $frontend_language = isset($modx->config['fe_editor_lang']) ? $modx->config['fe_editor_lang']:"";
            $tinymce_language = getTinyMCELang($frontend_language);
            $html = getTinyMCEScript($elementList,$webtheme,$width,$height,$tinymce_language,$frontend,$base_url, $webPlugins, $webButtons1, $webButtons2, $webButtons3, $webButtons4, $disabledButtons, $tinyFormats, $entity_encoding, $entities, $tinyPathOptions, $tinyCleanup, $tinyResizing, $tiny_css_path, $modx->config['tinymce_css_selectors'], $modx->config['use_browser'], $webAlign, null, null, $tinyLinkList);
          } else {
            $frontend = 'false';
            $manager_language = $modx->config['manager_language'];
            $tinymce_language = getTinyMCELang($manager_language);
            $html = getTinyMCEScript($elementList, $modx->config['tinymce_editor_theme'], $width='100%', $height='400px', $tinymce_language, $frontend, $modx->config['base_url'], $modx->config['tinymce_custom_plugins'], $modx->config['tinymce_custom_buttons1'], $modx->config['tinymce_custom_buttons2'], $modx->config['tinymce_custom_buttons3'], $modx->config['tinymce_custom_buttons4'], $disabledButtons, $tinyFormats, $entity_encoding, $entities, $tinyPathOptions, $tinyCleanup, $tinyResizing, $tiny_css_path, $modx->config['tinymce_css_selectors'], $modx->config['use_browser'], $modx->config['manager_direction'], $advimage_styles, $advlink_styles, $tinyLinkList);

    I only pasted the bits of code where I actually made changes. I deliberately didn’t paste the whole plugin code as I did this from the 096RC base. There may be changes by the time the final 096 is released. Take this as an exercise of "spot the difference" and take it from there. smiley
    • BTW, any chance you could use TobyL in your code comments? The JJC is confusing since it is also my initials... smiley
      • grin Sorry about that smiley Not trying to impersonate you,... honest smiley