Start page
Start page

Start page / Template development / Variables / Contexts / Special cases

Special variable properties

After displaying the variable and context concept in FirstSpirit on the previous pages, features of some variables and where they are defined will be presented in the following:

Variables in schedules, project settings and menu levels

 

As the table on the previous page shows, the contexts SITE-STORE and root have overlapping points.

The variables are evaluated in the preview in the following order:

  1. Structure variables
  2. Variables in project settings

If a variable is defined in the project settings and in menu levels with the same name, it is available in both the root context (here the value assigned via the project settings is used) and in the SITE-STORE context (here the value assigned via the menu level is used). Without using #global.context(...) (see the Project-related contexts page), the value assigned via the menu level is output in the preview for the variable, since by default the variable in the lowest context is taken into account.

In the case of structure variables, it is also important to note that they are displayed only in the preview of page references (also Site Store), but not of pages (Page Store).

Structure variables on a generated page can be overwritten by schedule variables: if schedule variables are set, they are read out on the generated page and overwrite variables with the same name that are defined on the root nodes of the Site Store or in the project settings.

Important Only variables that are defined at the root node level of the Site Store are overwritten. In the following cases, structure variables are not overwritten by schedule variables with the same name:
- structure variables defined at the menu level that are under the root node,
- structure variables defined at the root node level, but that have been changed at the menu level below it.

Refer also to the page on Structure variables.

For instance, this can be used to obtain a difference between the preview and the generated website (or parts of it, "Generate partial project" schedule) or between different generation schedules.

If variables from the project settings are evaluated during generation, neither schedule nor structure variables are permitted to be set.

Contexts: SITE-STORE vs. root

Fig. 1: Site Store context vs. global context (click to enlarge)

Examples of overwriting variables:
If the variable A in a menu level, in the project settings and in a generation schedule is defined using different values for each, the value defined in the Site Store applies in the preview, and the value defined in the schedule applies on the generated page (although only for values defined at the root node level of the Site Store, Fig. 1 : cases 1 and 2).

If no schedule variable is defined, the value defined in the Site Store applies on the generated page (case 3).

The value of the variable from the project settings is used only if no schedule or structure variables are defined (case 4).

Variables in format templates

The content of format templates or scripts can be integrated in other template types (such as page or section templates) using the $CMS_RENDER(...)$ instruction in combination with the template or script parameter; for example:

$CMS_RENDER(template:"IDENTIFIER")$

The IDENTIFIER is the abbreviation for the format template or script to be integrated.

Setting and outputting variables in format templates
Due to the availability of variables in lower contexts, it is also possible to access variables, for instance, that are present in page or section templates within format templates: if, for instance, the variable gv_page is defined in a page template:

$CMS_SET(gv_page, "Variable in page context")$                                                                                                             (page template)

it can be accessed in a format template integrated in the page template using the $CMS_RENDER(...)$ call and thus output, for example, using

$CMS_VALUE(gv_page)$                                                                                                                                                        (format template)
Important As already shown previously, it is of course important to define the variable gv_page before the $CMS_RENDER(...)$ call.

Variables defined in the format templates, however, are by default not available in the (higher) page context. This means that variables that are defined in format templates cannot be accessed in page templates. It is therefore only possible to output via the format template itself and not via the page template.

If, for instance, the variable gv_form is defined in a format template:

$CMS_SET(gv_form, "Variable in format template context")$                                                                                        (format template)

it can only be output via the format template; for example:

$CMS_VALUE(gv_form)$                                                                                                                                                        (format template)

To make a variable that has been defined in a format template available in a page context as well, the context:"this" parameter can be added to the $CMS_RENDER(...)$ call.

Important However, when doing so, it is important to note that variables made available this way can be unintentionally overwritten in a different context.

If, for instance, the variable gv_form is defined in a format template:

$CMS_SET(gv_form, "Variable in format template context")$                                                                                       (format template)

it can be accessed in the page template using the following $CMS_RENDER(...)$ call:

$CMS_RENDER(template:"IDENTIFIER", context:"this")$                                                                                                     (page template)

and thus output, for instance, using

$CMS_VALUE(gv_form)$                                                                                                                                                           (page template)
Contexts, context:

The same of course also applies to section templates and scripts.

Variables in links

 

Another common use case for nested contexts is to use link templates in the DOM editor (CMS_INPUT_DOM).

Contexts: DOM with link

Fig. 2: Contexts in links

By default, links inherit variables in DOM editors from higher contexts, i.e. variables that were previously initialized, for instance in the page or a section in which the DOM editor is used with a link template, can be used in the link template itself. Fig. 2 is a schematic drawing showing the validity of variables/values in link templates within a DOM editor.

This shows the validity of variables when they are initialized in a form or presentation channel:

  • pt_var_form: a variable initialized in the form of a page template
  • pt_var_out: a variable initialized in the presentation channel of a page template (e.g. via $CMS_SET(...)$)
  • st_var_form: a variable initialized in the form of a section template, specifically in the CMS_INPUT_DOM input component
  • st_var_out: a variable initialized in the presentation channel of a section template (e.g. via $CMS_SET(...)$)
  • link_var_form: a variable initialized in the form of a link template
  • link_var_out: a variable initialized in the presentation channel of a link template

Important In the link template, outputting the content of the DOM editor of the page or section containing the link is not recommended, since this would result in an infinite loop (in Fig. 2: st_var_form, indicated by the dotted line).
In general, it never makes sense to output external context to internal context.
 

Thus, by default, values that the editor enters in a link (in Fig. 2: link_var_form) are only available in the context of the link. These values can also be made available in the next higher section or page context by using #global.context("NAME"):

$CMS_SET(#global.context("section")["link_var_form"],link_var_form)$

or

$CMS_SET(#global.context("PAGE")["link_var_form"],link_var_form)$

As with other FirstSpirit objects, variables in a link can be overwritten by using $CMS_SET(...)$. This applies both to variables used as identifiers for input components on the "Form" tab of the link template as well as for variables that are defined in a presentation channel of the link template using $CMS_SET(...)$, for example. An example of applying this might be an auto completion or auto correction, e.g. for e-mail addresses (also refer to the example for e-mail links). In this case, a check is first made to determine if the editor entered an e-mail address with the required “mailto:” information in the lt_reference input component. For instance, if “mailto:” is missing, it is added automatically.

$CMS_IF(!lt_reference.startsWith("mailto:"))$
$CMS_SET(lt_reference, "mailto:"+lt_reference)$
$CMS_END_IF$

Variables in the Global content area

Fig. 3: Structure of the Global content area

Content of a global page (and possibly of the sections integrated in the global page) is output in the desired template using $CMS_VALUE(#global.gca("IDENTIFIER"))$. For the IDENTIFIER placeholder, the reference name of the Global content area page to be output must be specified. The content of the corresponding template is inserted where the $CMS_VALUE(#global.gca("IDENTIFIER"))$ call is located, and the context of the global page is started. Contexts are also nested in this case.

Fig. 2 shows a simplified structure of a page with a section in the Page Store (“PS”) with a page and section from the Global content area (“GCA”). Even here you can find “external” elements (such as a page in the Page Store) and “internal” elements (e.g., the section in the Global content area).

Fig. 4: Contexts of the Global content area

This nesting makes it possible to overlap or overwrite the contexts of sections, since, for instance, the (PS) section and (GCA) section each have a context called section. The (PS) page and (GCA) page on the other hand each have their own context. In this case, only the context of the “innermost” section, and thus usually the section from the Global content area, is addressed using #global.context("section").
The ID and the reference name of the page or section from the Page Store or Global content area can be output using #global.page.id and #global.page.name or #global.page.uid or #global.section.id and #global.section.name respectively.

Variables defined in the page and section templates on which the (PS) and (GCA) pages or (PS) and (GCA) sections are based apply to the current page or section as well as to all internal elements by default. If a variable is also to be made available to the external elements, #global.context("PAGE") can be used for this purpose.

If variables with the same identifier are defined in the page and section templates, the variable of the current element is always used. This means that in every template, variables defined in this template can be accessed with familiar instructions (also refer to Variables in templates).

To ensure that the variables of the current element and other elements can be accessed via any of the templates for the page and sections from the Page Store and from the Global content area, unique variable identifiers should be selected in the templates.

Variables in nested input components

Contexts in nested input components

Fig. 5: Nested input components (click to enlarge)

The FS_LIST, INLINE type input component with source="SECTIONTEMPLATES" is used to create lists of sections that are based on different section templates.

Depending on the configuration, sections (multiple) are nested within each other (Fig. 4). Section A, which is added below the page, can be described as an “external” section. The sections B through E, which are created by using FS_LIST, can be described as “internal” sections.

Nested contexts

Fig. 6: Contexts of nested input components

The content of FS_LIST is output in the desired template with $CMS_VALUE(IDENTIFIER)$. For this purpose, the variable identifier of FS_LIST has to be output for the IDENTIFIER placeholder. in the Fig. 4 example, e.g. the sections A and B each contain an FS_LIST component whose content is output in section A or section B. The context of the “next”, internal section begins here instead of the $CMS_VALUE(IDENTIFIER)$ call, (also refer to Fig. 5).

This nesting makes it possible to overlap or overwrite contexts of sections.

In the FS_LIST example, the external and internal sections have a shared context with the technical identifier section, for instance. In this case, entering the variable identifier makes it possible to access all variables defined in the associated section template or in a higher level context in any section, regardless of whether the section is external or internal. If a variable with the same identifier is present in multiple contexts (a variable with the same identifier is defined in an internal and external section or in the page, for instance), the variable of the current section is always used.

If a variable is also to be made available in external sections, the following can be used

$CMS_SET(#global.context.parentContext.parentContext["VALUE"], IDENTIFIER)$ 

(also refer to #global.context("NAME")).

To ensure that the variables of the current and other sections can be accessed via any of the section templates for the external and internal sections, unique variable identifiers should be selected in the section templates.

To avoid finite loops, a section with the same section template cannot be added to any section. The number of selectable section templates can be limited by using the TEMPLATES / TEMPLATE tags.

Important Important note on nesting FS_LIST input components
Creating too many nested levels using FS_LIST could not only pose problems related to usability for editors and maintainability in development, but could also result in impaired performance. Experience has shown that nesting beyond 3 levels should be avoided, if possible.

In particular, nesting language-dependent input components with each other (i.e. language-dependent FS_LIST input components with language-dependent input components, also refer to the useLanguages parameter) by using FS_LIST, INLINE / SECTIONTEMPLATES type is not recommended. This could result in configurations that cannot be saved, particularly in combination with rules.

© 2005 - 2014 e-Spirit AG | All rights reserved. | Last change: 2013-08-01