Skip to main content

5. Page components

A page component is an instance of a component type, meaning: the component type is the template and the page component is the actual content.

image.png

What a page component is composed of, depends on the component type selected.
There are 4 required components.

Sort order
Controls the order of the components, when rendering the page.

Component type
The template to use when rendering.

Component tags (system field)

The tags that the component type makes use of. See the headers and scripts below.

Component template (system field)

The template that the component type makes use of.

There are a couple different optional components, and this list is not set in stone, it can be adjusted to match the needs of the defined component types.

Multiline text 1-4
Multiline text boxes.
Any new-line will be replace with an html break tag.
Prepending lines with a * will konvert them to an unordered list.
Prepending the entire text with a * will konvert all lines til items in an unordered list.

Image 1-2
Reference to a media file.
Has a preview attatched, that updates with the selection.

CSS classes
Classes to add to the component.
Can be used to control background/accent colors.

Codeunit
Could be a text field where the full name of a codeunit is written (wrapped in the appropiate manner), or a database lookup that hides the names of the available codeunits behind a descriptive name.

Cache output
Should the rendered component be cached in memory.
Do not enable this option, if the page contains information about the signed in user.

Configurations

The rendering engine uses a couple of configurations that live in the configurations for this entity.
Here is a table of all the available configurations, none of them have default values, but most are needed.

Name
Description
CmsBlock.CacheEnabledField Field in the page content entity, that enables caching of the output
CmsBlock.TemplateField Field in the page content entity, that Contains a Template ID or raw HTML

Sample setup:

image.png

Headers and scripts

The following code enables a couple of features:
Preview of mediafiles and component types.
Only displaying the fields that the component type uses.
Hiding a couple of system fields.

<script type="text/javascript" src="node_modules/lightbox2/dist/js/lightbox.min.js?2.11.5"></script>
<link href="node_modules/lightbox2/dist/css/lightbox.min.css?2.11.5" rel="stylesheet" type="text/css">

<style type="text/css">
#NB_DATA_COMPONENTPREVIEW, 
.mergedField .tableImages a:last-of-type {
    display: none;
}
</style>

<script type="text/javascript">
const MEDIA_SAGID = 5
const COMPONENT_SAGID = 4


function checkField(fname) { 
    if (getValue("COMPONENTTAGS").includes(fname)) {
        showField(fname)
        $("#VB_DATA_" + fname + "_MERGE").show()
    } else {
        hideField(fname) 
        $("#VB_DATA_" + fname + "_MERGE").hide()
    }
}
function handleTags() {
    setValueFromLookup(COMPONENT_SAGID, $("#DATA_COMPONENTTYPE").val(), "TAGS", "COMPONENTTAGS")
    setTimeout(setFieldVisibility, 500)
}
function setFieldVisibility() {
    checkField("TITLE")
    checkField("TEXT1")
    checkField("TEXT2")
    checkField("TEXT3")
    checkField("TEXT4")
    checkField("IMAGE1")
    checkField("IMAGE2")
    //checkField("IMAGE3")
    //checkField("IMAGE4")
    //checkField("VIDEO1")
    checkField("CODEUNIT")
    checkField("CACHEOUTPUT")
}
</script>
// Skjul systemfelter
hideField("COMPONENTTAGS")
hideField("COMPONENTTEMPLATE")
hideField("IMAGE1PATH")
hideField("IMAGE1ALT")
hideField("IMAGE2PATH")
hideField("IMAGE2ALT")

// Preview billeder
let setupPreview = field => {
    $("#DATA_" + field).on("change", () => {
        preview(field)
    })
    preview(field);
}
let preview = field => {
    if ($("#DATA_" + field + " option:selected").val() == "") {
        setValue(field + "PREVIEW", "")
        return
    }
    setValueFromLookup(MEDIA_SAGID, $("#DATA_" + field + " option:selected").val(), "IMAGE", field + "PREVIEW")
}
setupPreview("IMAGE1")
setupPreview("IMAGE2")

// Preview component
let setupPreviewType = field => {
    $("#DATA_COMPONENTTYPE").on("change", () => {
        previewType(field)
    })
    previewType(field)
}
let previewType = field => {
    if ($("#DATA_COMPONENTTYPE option:selected").val() == "") {
        setValue("COMPONENTPREVIEW", "")
        return
    }
    setValueFromLookup(COMPONENT_SAGID, $("#DATA_COMPONENTTYPE option:selected").val(), "PREVIEW", "COMPONENTPREVIEW")
}
setupPreviewType()

// Handle tags
$("#DATA_COMPONENTTYPE").on('change', () => {
   handleTags()
})
handleTags()