Magnolia Enriched Text Fields

I look at the output of Rich Text in Magnolia directly in the interface. I define the field as shown below:

@TabFactory("Content")
public void contentTab(UiConfig cfg, TabBuilder tab) {
    tab.fields(
            cfg.fields.text("title").label("Title"),
            cfg.fields.richText("subtitle").label("Subtitle")
    );
}

Inside a template, when information is stored in the JCR, it appears to encode data with HTML objects:

Title: ${content.title}
Subtitle: ${content.subtitle}

Outputs (source) ...

Title: The Title Field
Subtitle: <p>The Subtitle Field</p>

But should be output (source) ...

Title: The Title Field
Subtitle: <p>The Subtitle Field</p>

Is there a way to automatically encode Rich Text fields?

+4
source share
2 answers

The decoding function works: https://documentation.magnolia-cms.com/display/DOCS/cmsfn#cmsfn-DecodeHTML

[#if content.text?has_content]
    ${cmsfn.decode(content).text}
[/#if]
+1
source

XSS - , :

Title: ${content.title}
Subtitle: <p>${content.subtitle}</p>

( ) JS .

: https://documentation.magnolia-cms.com/display/DOCS/Component+definition. -, escapeHtml, .:)

: bashaus , , . :

[#if content.text?has_content]
    ${cmsfn.decode(content).text}
[/#if]

TL.DR: html- , .

0
source

Source: https://habr.com/ru/post/1648675/


All Articles