Plone 5.0 tinyMCE 添加默认内容
Add default content to tinyMCE in Plone 5.0
我正在使用 Plone 5.0 设置,我想以某种方式修改它,以便想要创建新页面的用户在他们的 TinyMCE 编辑器中有一个默认文本。
我对 Plone 很陌生,对不同语言的数量以及它们如何相互连接感到有点不知所措。因此,我不想快速而肮脏地处理一些文件,而是想就如何正确有效地开始处理问题提出一些建议。
欢迎提出任何建议,如何处理。
前端(在本例中为 TinyMCE)不负责默认值,它是下面的形式。
Plone 5 使用具有 z3c 形式的 Dexterity 类型。
编辑:这就是你用老派的方式做这件事的方式——我的意思是 plone 指令方式——
对不起误导你了。我还是用plone.directives
,支持这种默认值适配器
plone.app.contenttypes 的默认内容类型 Document
正在使用 plone.supermodel。这有不同的概念。
如果您仍然愿意创建自己的 Richtext 行为,您可以按照以下说明操作:http://docs.plone.org/external/plone.app.dexterity/docs/advanced/defaults.html
你的情况:
def richtext_default_value(**kwargs):
return RichTextValue('<p>Some text</p>')
@provider(IFormFieldProvider)
class IRichText(model.Schema):
text = RichTextField(
title=_(u'Text'),
description=u"",
required=False,
defaultFactory=richtext_default_value,
)
model.primary('text')
您可以在文本字段中添加 defaultFactory
。
如果你把鸡蛋上的那些线砍下来,它就会起作用。
以下是有关以编程方式设置默认值的一些信息:
- https://pypi.python.org/pypi/plone.directives.form#id8
- How do you override the default value of a field in a dexterity behavior in Plone?
所以在你的情况下,这可能看起来像这样:
from plone.directives.form import default_value
from plone.app.contenttypes.behaviors.richtext import IRichText
from plone.app.textfield.value import RichTextValue
@default_value(field = IRichText['text'])
def richtext_default_value(data):
return RichTextValue('<p>Some text</p>')
您可以通过 context
参数扩展 default_value 装饰器以更具体:@default_value(field = IRichText['text'], context=my.package.content.interfaces.IMyType)
但是因为我们有行为的概念,所以使用默认值实现您自己的 Richtext 行为可能会更好:
- 创建行为 --> http://docs.plone.org/external/plone.app.dexterity/docs/behaviors/creating-and-registering-behaviors.html AND the plone default richtext behavior as template for your own -> https://github.com/plone/plone.app.contenttypes/blob/1.2.16/plone/app/contenttypes/behaviors/richtext.py
- 通过 ZMI(portal_types -> 文档)从您的内容类型(文档)中删除 ´plone.app.contenttypes.behaviors.richtext.IRichText` 行为(portal_types -> 文档)
- 添加您自己的 Richtext 行为,这可能类似于
my.package.behaviors.richtext.IRichtextWithDefaultValue
。
我正在使用 Plone 5.0 设置,我想以某种方式修改它,以便想要创建新页面的用户在他们的 TinyMCE 编辑器中有一个默认文本。
我对 Plone 很陌生,对不同语言的数量以及它们如何相互连接感到有点不知所措。因此,我不想快速而肮脏地处理一些文件,而是想就如何正确有效地开始处理问题提出一些建议。
欢迎提出任何建议,如何处理。
前端(在本例中为 TinyMCE)不负责默认值,它是下面的形式。
Plone 5 使用具有 z3c 形式的 Dexterity 类型。
编辑:这就是你用老派的方式做这件事的方式——我的意思是 plone 指令方式——
对不起误导你了。我还是用plone.directives
,支持这种默认值适配器
plone.app.contenttypes 的默认内容类型 Document
正在使用 plone.supermodel。这有不同的概念。
如果您仍然愿意创建自己的 Richtext 行为,您可以按照以下说明操作:http://docs.plone.org/external/plone.app.dexterity/docs/advanced/defaults.html
你的情况:
def richtext_default_value(**kwargs):
return RichTextValue('<p>Some text</p>')
@provider(IFormFieldProvider)
class IRichText(model.Schema):
text = RichTextField(
title=_(u'Text'),
description=u"",
required=False,
defaultFactory=richtext_default_value,
)
model.primary('text')
您可以在文本字段中添加 defaultFactory
。
如果你把鸡蛋上的那些线砍下来,它就会起作用。
以下是有关以编程方式设置默认值的一些信息:
- https://pypi.python.org/pypi/plone.directives.form#id8
- How do you override the default value of a field in a dexterity behavior in Plone?
所以在你的情况下,这可能看起来像这样:
from plone.directives.form import default_value
from plone.app.contenttypes.behaviors.richtext import IRichText
from plone.app.textfield.value import RichTextValue
@default_value(field = IRichText['text'])
def richtext_default_value(data):
return RichTextValue('<p>Some text</p>')
您可以通过 context
参数扩展 default_value 装饰器以更具体:@default_value(field = IRichText['text'], context=my.package.content.interfaces.IMyType)
但是因为我们有行为的概念,所以使用默认值实现您自己的 Richtext 行为可能会更好:
- 创建行为 --> http://docs.plone.org/external/plone.app.dexterity/docs/behaviors/creating-and-registering-behaviors.html AND the plone default richtext behavior as template for your own -> https://github.com/plone/plone.app.contenttypes/blob/1.2.16/plone/app/contenttypes/behaviors/richtext.py
- 通过 ZMI(portal_types -> 文档)从您的内容类型(文档)中删除 ´plone.app.contenttypes.behaviors.richtext.IRichText` 行为(portal_types -> 文档)
- 添加您自己的 Richtext 行为,这可能类似于
my.package.behaviors.richtext.IRichtextWithDefaultValue
。