Preview-related #global invocations
The preview of a page should frequently have other functions than the published (deployed) or generated status of this page. For example, status information or an editing function for the editor may be required within a preview.
A further requirement is language-dependent preview generation. For example, it is possible that the layout of a page differs depending on the language or that the language affects the output formatting. In addition, it is possible to prevent a special page from being generated in a specific presentation channel.
To fulfil these and other requirements the #global system object provides the option to access information in the preview, deployment and generation and to influence them.
The following table shows the preview-related operations:
Invocation | Meaning | Return data type |
---|---|---|
#global.context | Returns the current context. | |
#global.context("IDENTIFIER") | Returns a special context. | |
#global.dumpcontext | Output of all context information for easier troubleshooting/debugging | String |
#global.dumpcontext("SEPARATOR") | Output of all context information for easier troubleshooting/debugging, however with specification of separators for the output of the individual rows, e.g. <br>. | String |
#global.encoding | Returns the given HTML encoding for the language, which is currently being generated, e.g. ISO-8859-1, UTF-8. | String |
#global.isRelease | Determines whether the display of the object (e.g. page or page reference) is the release status or not. | Boolean |
#global.language | Returns the language currently being generated. | |
#global.language.abbreviation | Returns the abbreviation of the language currently being generated, e.g. DE, EN etc. | String |
#global.language.name | Returns the name of the language currently being generated, e.g. German, English etc. | String |
#global.now | Returns the current (today's) date. | |
#global.preview | Determines whether the display of the object (e.g. page or page reference) is a preview or not. | Boolean |
#global.project | Returns the project. | |
#global.project.id | Returns the project's ID. | |
#global.scheduleContext | Access to information of generation schedules: This call can be used to access the execution context of a generation schedule and therefore to access information such as the name of the project, the starting time of the schedule, the path to the generation directory, the number of errors during generation, etc. | |
#global.startDate | Synonym for #startdate | |
#global.version | Returns the FirstSpirit version number, e.g. 5.0.14 | String |
Enhanced error logging mode
The enhanced error logging mode is activated with the following expression:
$CMS_SET(#global.debugMode, true)$
Cancel a preview/generation
It is possible to prevent the generation of a preview or generation in a template. This is useful if generation is not wanted in the presentation channel of a page template (e.g. no PDF version of a document, etc.)
The expression to prevent generation is:
$CMS_SET(#global.stopGenerate, true)$
Examples
Several examples of use of the instruction within templates are shown in the following. The examples are intended to clearly show the specific effect of the instruction and provide help for the template developer when creating their own templates.
The examples displayed here must be adjusted for use within a project! For example, variable names must be changed to the specific variable names of the project in which the instruction is to be used. |
1st Example: Language-specific output of the date
$CMS_IF(#global.language.abbreviation == "DE")$
$CMS_VALUE(#global.now.format("dd.MM.yyyy"))$
$CMS_ELSE$
$CMS_VALUE(#global.now.format("MM/dd/yyyy"))$
$CMS_END_IF$
In the example, in the language with the abbreviation DE the current date is displayed in the notation Day, Month and Year - separated by a dot. For all other languages the current date is output in the notation Month, Day and Year.
Output for language with the abbreviation DE:
22.05.2007
Output for all other languages
05/22/2007
2nd Example: Greeting in the preview
$CMS_IF(#global.preview)$
Welcome to our Intranet site
$CMS_END_IF$
The sentence Welcome to our Intranet site is output in the preview.
3rd Example: Dynamic HTML framework
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$CMS_VALUE(#global.language.abbreviation.toLowerCase)$" lang="$CMS_VALUE(#global.language.abbreviation.toLowerCase)$">
<head>
...
<meta http-equiv="content-type" content="text/html; charset=$CMS_VALUE(#global.encoding)$" />
...
Depending on the generated language, the language abbreviation is used in lower case letters for XML language information.
Further, the given language encoding is used.
Output:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
...
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
...