Obtaining the “default” mockup TinyMCE configurati

2019-07-21 20:18发布

问题:

I'm trying to configure TinyMCE inside Plone 5 template (so: not the z3c.form widget type).

Using the TinyMCE Mockup patter you quickly learn how to display a rudimentary TinyMCE configuration (without any i18n support). But how I can get the "default" configuration applied to TinyMCE when it's loaded for default content types like a Plone page?

What I'm looking for a way to get the right value for the data-pat-tinymce HTML attribute.

回答1:

I think what you're asking for is to do something like this...

First, get the default tinymce pattern configuration:

from zope.component import getMultiAdapter
import json
pattern_options = getMultiAdapter(
  (context, request, None),
  name="plone_settings").tinymce()['data-pat-tinymce']
tiny_options = json.loads(pattern_options)

Then, manipulate the tiny_options dictionary and customize to your needs and provide it to your data-pat-tinymce attribute with json.dumps.



回答2:

Starting from @vangheem answer I found also an alternative way using mimetype select pattern.

You must configure the pattern with a JSON like this:

conf = {"textareaName": "text",
        "widget": {"text/html": {"pattern": "tinymce",
                                 "patternOptions": tiny_options}}}

...where tiny_options is the one taken from the accepted answer above and textareaName is the HTML textarea name where you want to activate TinyMCE.