We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6228
    • 249 Posts
    I searched the forums and couldn’t find any info on this, so ...

    I have a textarea TV that I use to enter html tags. The tag contents are injected into the page’s html head area. I use this TV in case a page requires a custom stylesheet, scripts, or what-not.

    I am trying to build a plugin that will read the contents of this TV, and inject the contents into the TinyMCE editor iframe at runtime. I would like this functionality so that the RTE editor pane mirrors the styles of the live site - even pages with unique stylesheets assigned to them.

    Does anyone know if this is possible? I created a plugin that fires on OnRichTextEditorInit, but don’t know exactly if there is a TinyMCE API object available, or some other object I can target to inject the contents in the appropriate area within the editor.

    Thanks
      lo9on.com

      MODx Evolution/Revolution | Remote Desktop Training | Development
      • 6228
      • 249 Posts
      Note: This solution does not read from TV tags, but it’s an acceptable compromise.

      Evo 1.0.3

      In Configuration -> Interface and Features, copy the value specified in ’Path to CSS file’, then empty this field. You will specify this value in our code.

      In Elements -> Plugins, open the TinyMCE plugin code for editing. Add the following immediately above the first $params statement:

      // BEGIN RUNTIME CSS INJECTION
      preg_match('/id\=(\d+)/', $_SERVER['QUERY_STRING'], $matches);
      $top = $modx->getParentIds($matches[1]);
      $top = (empty($top)) ? $matches[1] : array_pop($top) ;
      $doc = $modx->getPageInfo($top, 0, 'alias');
      $customparams = str_replace('[+pageid+]', $doc['alias'], $customparams);
      // END RUNTIME CSS INJECTION
      


      Then, click on the plugin’s configuration tab. Add the following to your Custom Parameters text area:

      content_css: 
      '/path/to/your/static/css/stylesheet.css, 
      /path/to/another/static/stylesheet1.css, 
      /path/to/your/page-specific/stylesheet/directory/[+pageid+].css',
      


      Usage:

      Place the value you copied from ’Path to CSS file’ into the content_css string, replacing the static path samples in the code. You can add additional ’static’ stylesheets if you want.

      When creating your page-specific stylesheets, organize them into one directory on your server. Update the directory path sample in the code to reflect your page-specific stylesheet directory. Naming your stylesheets is important: the stylesheet name must match the URL alias of the resource. For example, if I have a resource with a URL alias as ’my-great-page’, TinyMCE will look for a stylesheet called ’my-great-page.css’. One important note is that if the resource is nested in containers, TinyMCE will use the resource’s ultimate parent URL alias.

      Hope this helps someone.

      - Mike
        lo9on.com

        MODx Evolution/Revolution | Remote Desktop Training | Development