Override only the Description field of the standard Plone content type

I would like to override only the "representation of the" classic "description field" of the standard Plone content type (Document, Folder, blabla), so I need to "structure" the text of this field with structured text, for example

This is my description<br/> with many lines<br/> bla bla<br/> 
+7
source share
3 answers

Changing the template that displays the standard description field for converting strings to breaks is not difficult, but requires a little attention to avoid creating a security hole.

Override the kss_generic_macros.pt layer skin template either in the theme product or in a special folder.

You can then use Products.PythonScripts.standard.newline_to_br to convert strings to strings. You will need to insert the converted text with a "structure" to avoid breaking out of the gaps.

Since you will use the "structure", you must also manually remove the html description (use html_quote from the standard) before applying newline_to_br, or you will create a vector to attack XSS.

The key section of the macro, when fixed, can read:

  <div metal:define-macro="description-field-view" id="parent-fieldname-description" tal:define="kss_class python:getKssClasses('description', templateId='kss_generic_macros', macro='description-field-view'); pps modules/Products.PythonScripts.standard" tal:condition="context/Description" tal:attributes="class string:documentDescription$kss_class;"> <span metal:define-slot="inside" tal:replace="structure python:pps.newline_to_br(pps.html_quote(context.Description()))">Description</span> </div> 
+6
source

If you want to customize the description widget for all types of content, you could create an adapter using archetypes.schemaextender (in particular, the ISchemaModifier interface), for example this:

 from my.product.browser.interfaces import IMyProductLayer from my.product.widgets import MyCustomWidget from Products.ATContentTypes.interface.interfaces import IATContentType from archetypes.schemaextender.interfaces import IBrowserLayerAwareExtender from archetypes.schemaextender.interfaces import ISchemaModifier class MyExtender(object): # you could choose a more specific interface for a more fine grained override adapts(IATContentType) implements(IBrowserLayerAwareExtender, ISchemaModifier) # this will limit out override to this browserlayer layer = IMyProductLayer def fiddle(self, schema): # if you want to customize just the template of the original widget # see links below schema['description'].widget=MyCustomWidget( label='...', .... ) return schema 

and then you can register it as follows:

 <adapter factory=".extender.MyExtender" provides="archetypes.schemaextender.interfaces.ISchemaModifier" /> 

Remember to register your browser level . IMyProductLayer or this adapter will never be used.

Additional Information:

+4
source

You really don't want HTML in the description field. This field is used in many places and expects plain text.

It is best to use the above approach to add an extra field with a different name.

+4
source

All Articles