Search code examples
plonearchetypestemplate-talzpttemplate-metal

Override only the Description field of the Plone standard content type


I would like to ovverride only the "view" of the classic "description field" of the Plone standard content type (Document, Folder, blabla), cause I need to "structure" the text of this field with structured text like:

This is my description<br/>
with many lines<br/>
bla bla<br/>

Solution

  • Changing the template that renders the standard description field to convert newlines to breaks isn't hard, but will require a little care to avoid creating a security hole.

    Override the skin layer kss_generic_macros.pt template, either in a theming product or the custom folder.

    Then, you may use Products.PythonScripts.standard.newline_to_br to convert newlines to breaks. You'll need to insert the converted text with "structure" to prevent escaping of the breaks.

    Since you'll be using "structure," you absolutely must also manually html escape the description (use html_quote from standard) before applying newline_to_br, or you'll create a vector for a XSS attack.

    The key section of the macro, when fixed, might 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>