Start page / Templates (basics) / Composition of templates / Link templates / Examples / Dataset links
Example: dataset link form
FirstSpirit also permits links to datasets from the data store. An example of how these can be used is to use database content for tool tips, e.g. to display glossaries for words or phrases tagged by the editor as a link.
The following shows an example of a form and the syntax for corresponding output for a dataset link. The link target is a dataset of a data source in the project with glossary content or a column of a dataset. The text in this column can be displayed as a tool tip for a word when the user's mouse hovers over it.
Display (SiteArchitect)
Explanation
Use | Input component in the following code example | |
---|---|---|
1. | Input or selection of the glossary term. | lt_text |
2. | Selection of a dataset whose text is displayed as a tool tip when mousing over the word marked as a link. | lt_reference |
The FS_DATASET input component type used for lt_reference in this example cannot be used for the link text; therefore, the help field (under 1.) is required. A hidden input component with preset="copy" and a fallback value can also be used. |
Form
<CMS_MODULE>
<CMS_INPUT_TEXT name="lt_text" hFill="yes" maxInputLength="155" singleLine="no" useLanguages="no">
<LANGINFOS>
<LANGINFO lang="*" label="Text"/>
</LANGINFOS>
</CMS_INPUT_TEXT>
<FS_DATASET name="lt_reference" allowDelete="no" allowEdit="no" allowNew="no" hFill="yes" useLanguages="no">
<LANGINFOS>
<LANGINFO lang="*" label="Dataset"/>
<LANGINFO lang="DE" label="Datensatz"/>
</LANGINFOS>
<SOURCES>
<CONTENT name="glossar"/>
</SOURCES>
</FS_DATASET>
</CMS_MODULE>
Output
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>
For the link text in the HTML output, the value that was marked in a CMS_INPUT_DOM input component should be used and is stored in lt_text.
Let us assume that the data source from which the glossary information is to be selected contains a cs_description column in which the explanations for the terms are maintained. The information from the column is accessed using the getDataset method (see DatasetContainer data type) in combination with getFormData (see FirstSpirit Access API, de.espirit.firstspirit.access.store.contentstore, Interface Dataset package and de.espirit.firstspirit.access.store.pagestore, Interface DataProvider package) and the identifier of the input component (cs_description). The content of the column can then simply be output to a tool tip using the title tag of the link:
<a ... title="$CMS_VALUE(lt_reference.dataset.formData.cs_description)$">
A CMS_INPUT_TEXT or CMS_INPUT_TEXTAREA input component is available in the table template (identifier cs_description) that can be used to display the descriptive text as a tool tip.
In our example, a page with the reference name glossary can be used as a link target on a page on which the glossary entries are output. In this case it is a content projection (page with integrated data source); for more information, also refer to $CMS_REF(...)$, contentId parameter.
The character * placed after the tag is a simple way to identify it as a glossary entry.
A simple example of the link output could ultimately look like the following:
<a href="$CMS_REF(pageref:"glossar", contentId:lt_reference.dataset.formData.fs_id)$"
title="$CMS_VALUE(lt_reference.dataset.formData.cs_description)$">
<strong>
$CMS_VALUE(lt_text)$
</strong>
</a>*