Start page / Templates (basics) / Composition of templates / Link templates / Examples / Internal links

Example: form for internal links

Internal links refer to objects within the current project, such as pages/references, media or datasets, thus fulfilling a standard requirement in web projects: the linking of objects within a project.

The following shows an example of a form and the syntax for corresponding output for a link that leads to a different page in the project and, if necessary, to a section of that page.

Display (SiteArchitect)

Dialog internal link

Explanation

 

Use

Input component in the following code example

1.

Selection of a page from the site store and, if applicable, of a section on this page to which the link leads when the user clicks on it.
(Mandatory field, see Introduction)

lt_reference

2.

Input of a link text.
(Mandatory field, see Introduction)

lt_text

3.

Input of an optional comment, which can be displayed as a tool tip for the link.

lt_comment

4.

Selection of the language version in which the page is to be opened. This enables linking to a page in another language version, for instance, if the page does not yet exist in the language of the output page.

lt_language

   

Form

<CMS_MODULE>

<FS_REFERENCE name="lt_reference" hFill="yes" useLanguages="no">
<FILTER>
<ALLOW type="pageref"/>
</FILTER>
<LANGINFOS>
<LANGINFO lang="*" label="Target"/>
<LANGINFO lang="DE" label="Ziel"/>
</LANGINFOS>
<PROJECTS>
<LOCAL name=".">
<SOURCES>
<FOLDER name="root" store="sitestore"/>
</SOURCES>
</LOCAL>
</PROJECTS>
</FS_REFERENCE>

<CMS_INPUT_TEXT name="lt_text" hFill="yes" singleLine="no" useLanguages="no">
<LANGINFOS>
<LANGINFO lang="*" label="Link text"/>
<LANGINFO lang="DE" label="Verweistext"/>
</LANGINFOS>
</CMS_INPUT_TEXT>

<CMS_INPUT_TEXT name="lt_comment" hFill="yes" singleLine="no" useLanguages="no">
<LANGINFOS>
<LANGINFO lang="*" label="Comment"/>
<LANGINFO lang="DE" label="Kommentar"/>
</LANGINFOS>
</CMS_INPUT_TEXT>

<CMS_INPUT_COMBOBOX name="lt_language" hFill="yes" singleLine="no" useLanguages="no">
<CMS_INCLUDE_OPTIONS type="language"/>
<LANGINFOS>
<LANGINFO lang="*" label="Language"/>
<LANGINFO lang="DE" label="Sprache"/>
</LANGINFOS>
</CMS_INPUT_COMBOBOX>

</CMS_MODULE>

Form configuration information:

The lt_reference input component (FS_REFERENCE type) is used with the input of

<FILTER>
<ALLOW type="pageref"/>
</FILTER>

to select only page references from the current project.

Output

Important The following shows examples of only the minimum amount of code that is needed for suitable adaptation in a production project. Thus, for instance, a Not Empty check (e.g. $CMS_IF(!lt_reference.isEmpty)$ is not performed. Without this check, however, generation errors could occur in the production project.

Links are generally output in HTML using the following syntax:

<a href="[Linktarget]">[Linktext]</a>

The value of lt_reference is used for the link target in the HTML output via the link template. The value of lt_text is used for the link text:

<a href="$CMS_REF(lt_reference)$">$CMS_VALUE(lt_text)$</a>

In order to jump to a section of the page (anchor) selected by the editor, the reference name of the selected section is defined using getSectionName and is output with the # character.

Important To use the anchor functionality in FirstSpirit when using FS_REFERENCE in the desired section templates, the <a> tag needs to be activated in the “File extension” area of the “Properties” tab.

Comments from the lt_comment field can be output as a tool tip for the link using the title HTML attribute.

As the final step, the link target language selected by the editor using lt_language can be output and taken into account. The language attribute is used for resolving the reference (see also $CMS_REF(...)$). This attribute expects a valid language code for the project as the value, such as DE or EN, which is exactly what the editor can specify using the relevant combo box in the form. The selected and saved value can be read out using the getKey method.

A simple example of the link output could ultimately look like the following:

 <a href="$CMS_REF(lt_reference, language:lt_language.getKey())$#$CMS_VALUE(lt_reference.getSectionName())$"
title="$CMS_VALUE(lt_comment)$">
$CMS_VALUE(lt_text)$
</a>

Schema

Internal link input and output
 

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