mareike
Returning Observer

CaaS INPUT_DOM to JSON without manually adapting each section template

Hey everybody,

we are currently setting up our templates for the FS CaaS and creating JSONs from the templates.
In most examples we found online, the JSON output is made directly in every section template and the values of inputs are mapped like this:

{ 
"text": $CMS_VALUE(text.toHtml().toJSON())$
}

We think this is a rather expensive way of creating the JSON because we would have to adapt each section template.
Instead we go with this line in the CaaS-tab of the page template

$CMS_VALUE(json(#global.page))$

which generates all inputs and child sections with its input values.
The problem is: when there is an input field that is an CMS_INPUT_DOM, the value is missing the html-tags, because we have no possibility to parse the content to html before prasing it to JSON.
Is there a handy way of implementing the JSON values of the templates while keeping the value of CMS_INPUT_DOM correctly? Is it really the recommended way to go to adapt each section template with a custom JSON output?

0 Kudos
1 Reply
hoebbel
Crownpeak employee

Dear Mareike,

if you are creating JSON with the template source code, did you define the template content within the format templates (e.g.

<p>$CMS_VALUE(#content)$</p>

für the p format-template)?

As long as the JSON is created with the use of the template source code (regardless, if #global.json.sectionTemplateRendering is activated or not), the content of a CMS_INPUT_DOM is created as HTML defined by the appropriate format templates used within the editor.

It should look like this:

{"fsType":"CMS_INPUT_DOM","name":"st_input_dom","value":"<p>Absatz<\/p><p><b>Fett<\/b><\/p><p>\"<i>Kursiv<\/i>\"<\/p><p><a href=\"https:\/\/heise.de\">Heise<\/a><\/p>"}

If you want to have exactly this, but it doesn't work, then please post the source code you use in the format templates (especially in the "p" template) and the JSON that is generated.

Best regards

Holger