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

Example: download link form

Download links offer the ability to download media from an Internet site to the workstation.

The following shows an example of a form and the syntax for the corresponding output for a link that downloads a medium from the media store, such as a Microsoft Word file. The link text should either be text that the editor can enter in the field himself or it should be the file name (“File name” field of the file from the media store). The size and file format should also be output automatically.

Display (SiteArchitect)

Dialog download link

Explanation

 

Use

Input component in the following code example

1.

Selection of a medium from the media store which is downloaded when the user clicks on the link text.
(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

   

Form

<CMS_MODULE>

<FS_REFERENCE name="lt_reference" hFill="yes" useLanguages="no">
<FILTER>
<ALLOW type="media"/>
</FILTER>
<LANGINFOS>
<LANGINFO lang="*" label="Download"/>
</LANGINFOS>
<PROJECTS>
<LOCAL name=".">
<SOURCES>
<FOLDER name="root" store="mediastore"/>
</SOURCES>
</LOCAL>
</PROJECTS>
</FS_REFERENCE>

<CMS_INPUT_TEXT name="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="comment" hFill="yes" singleLine="no" useLanguages="no">
<LANGINFOS>
<LANGINFO lang="*" label="Comment"/>
<LANGINFO lang="DE" label="Kommentar"/>
</LANGINFOS>
</CMS_INPUT_TEXT>

</CMS_MODULE>

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>

For the link target (in this case the medium that can be downloaded), the the value of lt_reference is used in the HTML output via the link template. If the editor has entered a link text in the lt_text input component, this is used. Otherwise, the text from the medium's “Description” field is output (using ref(...)):

<a href="$CMS_REF(lt_reference)$">

$CMS_IF(!lt_text.isEmpty)$
$CMS_VALUE(lt_text)$

$CMS_ELSE$
$CMS_VALUE(ref(lt_reference).getDescription())$

$CMS_END_IF$
$CMS_VALUE(ref(lt_reference).getDescription())$

$CMS_END_IF$
</a>

This information can be determined automatically for each downloadable file using getSize and getExtension so that the user immediately knows the file format and size

$CMS_SET(_fileSize, ref(lt_reference).getSize().humanReadable("KiB", "#,##0"))$
$CMS_SET(_fileInfo, " (" + ref(lt_reference).getExtension().upperCase + ", " + _fileSize + " KB)")$

and then the information can accordingly be output using the link text:

$CMS_VALUE(_fileInfo)$

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

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

$CMS_SET(_fileSize, ref(lt_reference).getSize().humanReadable("KiB", "#,##0"))$
$CMS_SET(_fileInfo, " (" + ref(lt_reference).getExtension().upperCase + ", " + _fileSize + " KB)")$

<li>
<a href="$CMS_REF(lt_reference)$" title="$CMS_VALUE(lt_comment)$">

$CMS_IF(!lt_text.isEmpty)$
$CMS_VALUE(lt_text)$

$CMS_ELSE$
$CMS_VALUE(ref(lt_reference).getDescription())$

$CMS_END_IF$

$CMS_VALUE(_fileInfo)$
</a>
</li>

Schema

Download link input and output
 

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