Introducing CXT / Templates / Defining fragments / Outputting content

Use / output

Table of contents

In principle, the options for deploying the content entered with the FragmentCreator and using or further processing it in other systems are extremely flexible due to the format-neutral data storage. FirstSpirit can be used by itself as the backend or it can be used in combination with any other system (keywords: “Headless CMS”, “Pull principle”).

Output via FirstSpirit backend

One way of deploying content from a fragment project is via a classic FirstSpirit project in which fragments from the fragment project are referenced. This takes place via an appropriately configured FS_INDEX input component (see Using fragments). For more information on FS_INDEX and its output, see also INDEX (→FirstSpirit Online Documentation).

The FirstSpirit project defines how the data from the referenced fragments is to be displayed (“rendered”).
In the output, the data stored in the input components of the fragments can be accessed via the respective identifier (in the examples on this page: “title” for the title, “language” for the language).

"Fragment" interface

getValues: output of data objects

Fragments that have been selected and stored via an FS_INDEX component are initially output via a $CMS_FOR(...)$ instruction and the getValues() method (in Bean syntax: .values), e.g.,

$CMS_FOR(fragment, st_fragments.values())$

where fragment is the variable name for this instruction and st_fragments is the identifier of the relevant FS_INDEX component.
Return object: List
(see also List (→FirstSpirit Online Documentation))

The following methods can be executed on this list:

getId

The system automatically assigns a unique ID for each fragment, which can be used to identify the fragment. This ID can be accessed using the getId method (in Bean syntax: .id), e.g.,

$CMS_VALUE(fragment.id)$

getRemote

The getRemote method (in Bean syntax: .remote) can be used to determine the symbolic name of the relevant fragment project as it is used in the remote configuration:

$CMS_VALUE(fragment.remote)$

"Variant" interface

getVariants

The variants are output via $CMS_FOR(...)$ and the getVariants() method (in Bean syntax: .variants). Iteration is performed over the variable identifier of the $CMS_FOR(...)$ instruction used to output the fragments (fragment in this example). By grouping value pairs into a map (see Map (→FirstSpirit Online Documentation)), iteration can be performed over the elements of the variant dimensions in the output:

$CMS_FOR(variant, fragment.variants({:}))$

getId

The system automatically assigns a unique ID for each variant, which can be used to identify this variant. This ID can be accessed using the getId (in Bean syntax: .id), for example

$CMS_VALUE(variant.id)$

getTitle

The title of a variant (see Metadata) can be accessed with the getTitle() method (in Bean syntax: .title) e.g.

$CMS_VALUE(variant.title)$

getFormData

The other values of a variant can be output via the getFormData() method (in Bean syntax: .formData) (see Access to FS_INDEX (→FirstSpirit Online Documentation)). Using the following simplified syntax, it is possible to access the content of a FormField in the language currently being rendered:

.formData.markdown

where markdown is the identifier of the input component in the fragment template whose content is to be accessed.

getTags

The tags of a variant (see pages FirstSpirit Tagging Editor and FS_TAGGING configuration) can be accessed with .getTags() (in Bean syntax: .tags).

Example:

$CMS_VALUE(variant.tags)$

Output example:

[#ceo, #teaser]

Returned object type: Collection

getProperties

It is possible to query the properties / variant dimension, e.g., the language dimension, of a variant with .getProperties() (in Bean syntax: .properties). These can be used for filtering.

Example:

$CMS_VALUE(variant.properties)$

Example output:

{language=EN}

Syntax example

The following is a example of a fragment/variant output:

$CMS_FOR(fragment, st_fragments.values())$
Fragment: $CMS_VALUE(fragment.id)$<br />
<ul>
$CMS_FOR(variant, fragment.variants({:}))$
<li>
Variante: $CMS_VALUE(variant.title)$<br />
$CMS_VALUE(variant.formData.text)$
</li>
$CMS_END_FOR$
</ul>
$CMS_END_FOR$

Output via a different backend

If a backend system other than FirstSpirit is to be used for the output, the template set of the fragment template must be used to define how the entered data is to be coded and stored. The data is fed into another system which is responsible for deploying and displaying (“rendering”) it.

JSON (JavaScript Object Notation) is used to exchange fragments between FirstSpirit CXT and FirstSpirit CaaS. For this purpose, the template set in the fragment project must be adapted accordingly. See also Single expression page rendering (→FirstSpirit Online Documentation) and Support for JSON (→Documentation for Administrators).

Output example (JSON)

Example of fragment/variant output via JSON:

{
"fragmentUUid": "$CMS_VALUE(#global.page.parent.uid.replaceAll("_","-"))$",
"documentUUid": "$CMS_VALUE(#global.page.uid.replaceAll("_","-"))$",
"variation": $CMS_VALUE(#global.page.meta("variations").toJSON())$,
"title": $CMS_VALUE(#global.page.meta("title").toJSON())$,
"text": $CMS_VALUE(text.toHtml().toJSON())$,
"url": "$CMS_VALUE(url)$"
}

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.4 | Data privacy