Start page / Templates (basics) / Composition of templates / Link templates / Examples / E-mail links

Example: e-mail link form

E-mail links do not send users to other web pages or files, but instead tell the web browser to launch an e-mail program or to prepare similar functionality to send electronic messages. Not all web browsers support this functionality to the same extent.

The following shows an example of a form and the syntax for corresponding output for an e-mail link that refers to the e-mail address info@e-spirit.com. The example is used both for including e-mail links and HTTP addresses. The user can choose which link type he wants to use. A rudimentary check verifies that the format of the link target entry is valid.

Display (SiteArchitect)

Dialog e-mail link

Explanation

 

Use

Input component in the following code example

1.

Input of an e-mail or HTTP address (e.g. info@e-spirit.com or www.e-spirit.com).
(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 link type: e-mail link or HTTP link

lt_linktype

   

Form

<CMS_MODULE>

<CMS_INPUT_TEXT name="lt_reference" hFill="yes" singleLine="no" useLanguages="no">
<LANGINFOS>
<LANGINFO lang="*" label="Target URL"/>
<LANGINFO lang="DE" label="Zieladresse"/>
</LANGINFOS>
</CMS_INPUT_TEXT>

<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_linktype" hFill="yes" preset="copy" singleLine="no" useLanguages="no">
<ENTRIES>
<ENTRY value="http">
<LANGINFOS>
<LANGINFO lang="*" label="HTTP link"/>
<LANGINFO lang="DE" label="HTTP-Verweis"/>
</LANGINFOS>
</ENTRY>
<ENTRY value="mail">
<LANGINFOS>
<LANGINFO lang="*" label="Mail link"/>
<LANGINFO lang="DE" label="E-Mail-Verweis"/>
</LANGINFOS>
</ENTRY>
</ENTRIES>
<LANGINFOS>
<LANGINFO lang="*" label="Reference type"/>
<LANGINFO lang="DE" label="Verweistyp"/>
</LANGINFOS>
</CMS_INPUT_COMBOBOX>

</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>

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_VALUE(lt_reference)$">$CMS_VALUE(lt_text)$</a>

First a check is run to determine whether it is an e-mail or an HTTP link (lt_linktype variable). Depending on this, it is possible to check whether the correct prefix has been entered, e.g. mailto: for e-mail links or http:// or https:// for HTTP links.

If it is an HTTP link (http value in the lt_linktype combo box),

$CMS_IF(lt_linktype.getKey() == "http")$

using the following,

$CMS_IF(!lt_reference.startsWith("http://") && !lt_reference.startsWith("https://"))$

a check is run to determine whether the input begins with http:// or https://. If not, the input is set to http:// by default:

$CMS_SET(lt_reference, "http://" + lt_reference)$

If it is an HTTP link (mail value in the lt_linktype combo box), using

$CMS_IF(!lt_reference.startsWith("mailto:"))$

a check is run to determine whether the input begins with mailto:. If not, the input is set to mailto: by default:

$CMS_SET(lt_reference, "mailto:"+lt_reference)$

Comments from the lt_comment field can be output as a tool tip for the link using the title HTML attribute. Tool tip options include outputting the target e-mail address or HTTP address. If the comment field is not filled, the link target (lt_reference) can be output as the fallback:

... title="$CMS_VALUE(if(!lt_comment.isEmpty, lt_comment, lt_reference))$" ...

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

$CMS_IF(lt_linktype.getKey() == "http")$

$CMS_IF(!lt_reference.startsWith("http://") && !lt_reference.startsWith("https://"))$
$CMS_SET(lt_reference, "http://" + lt_reference)$
$CMS_END_IF$

$CMS_ELSE$

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

$CMS_END_IF$

<a href="$CMS_VALUE(lt_reference)$"
title="$CMS_VALUE(if(!lt_comment.isEmpty, lt_comment, lt_reference))$">
$CMS_VALUE(lt_text)$
</a>

Schema

E-mail link input and output
 

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