CMS
The CMS system is available as of version 12764.
A demo is available at https://trainingv4.tsnocode.com/cms.
Managing content
How to manage content once the system is up and running.
1. Component types
Component types (templates) are defined in the entity "Component Types".
A component type is composed of 4 attributes:
The name Just the name shown in the dropdown, when selecting a component type for a page component.
The tags A list of system names for the fields that are used in the template. To disable caching of a component type, remove CACHEOUTPUT from the tags, and the field won't be available on those page components.
The preview image A sample image, that will be shown when selecting the component type for a page component.
The template Either: An ID of an HTML template, defined as a template in the designer. The raw HTML template.
When inputting content into the template the following syntax is used: The system name of the field, encapsulated in curly brackets, eg. {TITLE} .
Simple compares are available, eg. {IF_TITLE=ABC} . Must also have an end-tag, {ENDIF} . Can also make use of an else-tag, {ELSE} , eg. {IF_TITLE=ABC}
{SUBTITLE}
{ELSE}{ENDIF} .
Execution of page codeunits is also supported. Input the name of the codeunit, like you would in the url command-parameter, prefix with a @ and encapsulate in curly brackets, eg. {@com.tsnocode.codeunit.common.HelloWorld} . Execution of codeunits is the last instruction, when redering a component, thus it is possible to inject this value from an input field.
2. Media
User defined media (images or video), is defined in the entity "Media Files".
A media file is composed of 4 attributes.
The name Just the name shown in the dropdown, when selecting a component type for a page component.
The type Is it an image or a video.
The content An image or a video, based on the type selected.
An alt-text The alt-text added to the HTML, that will be shown if the media fails to load, and will be used by screen readers.
A media file also has 2 system attributes.
The public path A path to where this file is publicly available.
The alt public path Only used for videos. A path where a thumbnail for this video is publicly available.
Every time a media file is saved, the file is written to disk, and the public path is updated. If the media is a video, then the video is also re-encoded into the defined resolutions and bitrates . This takes a while and therefore the site will be loading for a little while. A thumbnail is also generated, and that path is saved in the field "Alt Path".
3. Pages
The browsable pages are defined in the "Pages" entity. A page consists of somebasic information and a list of components.
A page is composed of 8 attributes.
The name The name shown in the window title.
The path The url that a user should navigate to, to view this page. Gets auto-generated based on the title. Must be unique.
A description A description for the administrators. Is not outputted.
A list of components The actual content of the site.
CSS classes Classes to add to the body tag. Can be used to control background/accent colors.
A Wrapper The wrapper to use for this page.
A Stylesheet The stylesheet to use for this page.
Cache option Should the rendered component be cached in memory. Do not enable this option, if the page contains information about the signed in user.
At the top of the page there is a preview button. Clicking this will clear the cache and open the page, displaying the page as it would be, if navigated to by a user.
What a page component is composed of, depends on the component type selected. There are 2 required components.
Sort order Controls the order of the components, when rendering the page.
Component type The template to use when rendering.
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.
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.
Every time a page is saved, if the path changed, the system will add a redirect from the old path to the current one.
Saving a page or a component that is cached will not result in the cache being cleared.
4. Menu
The Basic Menu codeunit uses the structure defined in the "Menu" entity.
A menu item is composed of 5 attributes.
Sort order Used to control the order of the menu.
Parent element If this element should be nested under another menu item.
Title The title shown in the menu. Here it is a reference to a page.
Url The url to redirect to, when a user clicks the menu item. Here it is a copy of the path from the referenced page.
Sub elements If this menu item doesn't have a parent element, this element is available. Shows the list of elements to show in a dropdown un this menu element.
Updating a menu entry will not clear the cached output of the menu.
5. Redirects
Redirects are defined in the entity "Redirects".
A redirect is composed of 2 attributes.
From The url that a user accesses. The part after /p/ . Can't contain a ? and will only react to the part before the ? of the url that a user accessses. Eg. /p/some-page?param=foobar , will be seen as some-page .
To The url that a user should be redirected to. Can only be the part of the url that comes after /p/ .
Setup
How to setup and enable this feature.
1. General structure
To enable public access to the pages that are build using this, update the policy enablePublicCMSServlet to true.
The public pages are available on /p/[page-url] .
You might want to update the policy defaultLangingPage on the server to redirect the user to "p" instead of "login", so that the random user accessing the url directly, will see the public site, instead of the login page. This feature is available as of version 12793.
Entities
You can read the specific setup of the 6 entities in this feature on the following 6 pages.
Wrapper
A minimum of one wrapper has to be defined in the designer (Design -> Wrappers). The ID of the wrappers that should be available to the maintainer of the site, are needed in the Page entity.
The wrapper is where you include all the static files that are needed to make the site work, eg. bootstrap. You don't need to link the stylesheet, the engine will handle that.
Stylesheet
A minimum of one stylesheet has to be defined in the designer (Design -> Stylesheet). The ID of the stylesheets that should be available to the maintainer of the site, are needed in the Page entity.
Static files (javascript/css/icons)
If your site requires static files, eg. bootstrap, then these should be uploaded to Media files in the designer (Design -> Media files), not to the entity Media Files.
Upload the javascript and css files as "Other" and link to their public path from your wrapper(s).
System configurations (Static content)
The system is quite configurable. Here is a table of all the available configurations.
Name
Description
Default value
Cms.Media.Field.Type
Systemname of field that defines the type of media file (video/image)
TYPE
Cms.Media.Field.Image
Systemname of the field that contains the image for the media file
BILLEDE
Cms.Media.Field.Video
Systemname of the field that contains the video for the media file
VIDEO
Cms.Media.Field.Path
Systemname of the field that contains the public path for the media file
PATH
Cms.Media.Field.AltPath
Systemname of the field that contains the thumbnail or alt-image for the media file
ALTPATH
Cms.Media.Field.AltImage
Optional field. Systemname of the field that contains the alt image for the media file
BILLEDE1
Cms.Media.Folder.Public
The public root path where the media files are available
/media
Cms.Media.Folder.System
The path on the server, where the media files are supposed to be saved
/usr/share/tomcat9/webapps/media
Cms.Media.Video.HorizontalResolutions
The horizontal resolutions that the down-sampled videos should have. Must be same length as VerticalResolutions and in ascending order.
[1024,1280,1920]
Cms.Media.Video.VerticalResolutions
The vertical resolutions that the down-sampled videos should have. Must be same length as in ascending order.
[576,720,1080]
Cms.Media.Video.Bitrates
The Mbit rates that the down-samled videos should have. Must be same length as VerticalResolutions and in ascending order.
[2.0,4.0,8.0]
Cms.Menu.Entity
System name of the entity containing menu items. Used by the codeunit com.tsnocode.core.cms.BasicMenu.
menu
Cms.Menu.Field.Title
System name of the field containing the shown text in a menu item
TITLE
Cms.Menu.Field.Url
System name of the field containing the url that the menu item should link to
URL
Cms.Menu.Field.Parent
System name of the field that points to a parent menu item
CHILDREN
Cms.Menu.Field.Children
System name of the field that lists sub menu items
PARENT
Cms.Menu.Html.RootItemEmpty
HTML to generate a root menu item, with no children
*
Cms.Menu.Html.RootItem
HTML to generate a root menu item, with children
**
Cms.Menu.Html.ChildItem
HTML to generate a sub menu item
***
Cms.Page.Entity
System name of the entity containing the pages, when accessed from the public /p
pages
Cms.Page.Field.Url
System name of the field containing the page urls, when accessed from the public /p/[page-url]
URL
Cms.Redirects.Entity
System name of the entity containing redirect urls,when accessed from the public /p
redirects
Cms.Redirect.Field.From
System name of the field containing the called urls, when accessed from the public /p/[page-url]
FROM_VALUE
Cms.Redirect.Field.To
System name of the field containing the urls to redirect to, when accessed from the public /p/[page-url]
TO_VALUE
*)
***)
{TITLE}
2. Component types
A Component type is a template for a single block, that can be displayed by the CMS.
A component type is composed of 4 attributes:
The name Just the name shown in the dropdown, when selecting a component type for a page component.
The tags A list of system names for the fields that are used in the template. To disable caching of a component type, remove CACHEOUTPUT from the tags, and the field won't be available on those page components.
The preview image A sample image, that will be shown when selecting the component type for a page component.
The template Either: An ID of an HTML template, defined as a template in the designer. The raw HTML template.
3. Media File
A media file is a user updateable graphic, eg image or video.
A media file is composed of 7 or 8 attributes:
Type The type of media. Default is image and video.
A title An internal title, shown when selecting the image from a dropdown.
An image The image upload field.
An alternative image (optional) An optional second image upload field.
A video The video upload field.
The public path The public path, where the media was written.
The alternative public path The public path of the generated thumbnail, or the alternative image.
Alt text The alt text displayed if the media fails to load.
This entity makes use of a codeunit named com.tsnocode.core.cms.MediaEventHandler . The codeunit is controlled via the System configuration that start with Cms.Media. . If the media is a video, then the video is re-encoded into the defined resolutions and bitrates . This takes a while and therefore the site will be loading for a little while. A thumbnail is also generated, and that path is saved in the field "Alt Path".
4. Pages
A page is a page that a visitor of the site can view.
A page is composed of 6-9 attributes
The title The public title of the page. Possibly also used for menu's depending on how that entity is built.
The path The path/URL that maps to this page. The part after /p/ .
An optional internal description Just an internal description of the page.
A list of page components A actual content of the page. A list of child records .
Optionally some body-classes A place to add some custom css classes. Doesn't have to be a text input, could be a drop down instead, eg. with background colors.
A wrapper The ID of the wrapper that the page should use. Use an Enumeration or a sql-lookup .
A stylesheet The ID of the stylesheet that the page should use. Use an Enumeration or a sql-lookup .
Option to cache the output A yes/no that allows the content administrator to cache the rendered page, for faster browsing.
A "preview page"-button A button that calls the the codeunit com.tsnocode.core.cms.ShowPage to show what the page looks like to an end user.
Configuration
This entity makes use of a codeunit named com.tsnocode.core.cms.PageEventHandler to maintain redirects, when the path changes. The codeunit is controlled via the System configuration that start with Cms.Redirects. .
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
CmsPage.BlockListfield
Field in this entity, that contains the page content
CmsPage.CacheEnabledField
Field in this entity, that enables caching of the output
CmsPage.CssClassField
Field in this entity, that contains classes to add to the body tag
CmsPage.StylesheetField
Field in this entity, that contains the Stylesheet ID
CmsPage.TitleField
Field in this entity, that contains the name of the page
CmsPage.WrapperField
Field in this entity, that contains the Wrapper ID
Sample setup:
Headers and scripts
This is the simple script that helps build a path based on the given title.
$("#DATA_TITLE").on("change keyup", () => {
setValue("PATH", keepUrlSafeChars(getValue("TITLE")))
})
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.
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:
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.
// 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()
6. Menu
The structure used by the default BasicMenu codeunit, allowing the user to manage the contents of a menu. Optional feature.
A menu entry is composed of 5 attributes.
Sort order Controls the order of the components, when rendering the menu.
Parent entry The menu entry that this entry recides under.
Title The shown text on this menu entry. Either use a Data item , or a text field , to have full control.
Url/Path The url/path of the page, to redirect to. Can be external. Either use a subselect / value copy in combination with the title, or a text field , to have full control
Children A list of menu entries below this one. If this page does have a parent, this field is hidden, because the codeunit doesn't support multiple levels of menus.
This entity is used by a codeunit named com.tsnocode.core.cms.BasicMenu to render a simple menu. The codeunit is controlled via the System configuration that start with Cms.Menu. . The default configurations generate a bootstrap 4.6 navbar .
7. Redirects
The redirects are a map of old or custom urls that for some reason has to link to a different page. Optional feature.
A redirect it composed of 2 attributes.
From The old url/path. The part after /p/ .
To The url to redirect the user to. The part after /p/ . This doesn't support external redirects, but could in the future.
This entity is used by the redirect feature and the PageHandler-Codeunit . The feature and codeunit is controlled via the System configuration that start with Cms.Redirect. .
8. Default Codeunits
The platform ships with a couple default codeunits, that help manage the CMS data.
Basic Menu
Name: com.tsnocode.core.cms.BasicMenu Generates a dynamic menu, with option of one layer of sub-element, and marks the active page.
Page handler
Name: com.tsnocode.core.cms.PageEventHandler Helps maintain redirects, when a pages url changes, by automatically added the old url to the redirects entity.
Media handler
Name: com.tsnocode.core.cms.MediaEventHandler Helps write images and videos to disk, and down sampling videos.
Preview page
Name: com.tsnocode.core.cms.ShowPage Resets the cache and shows a page.