Start page / Template development / Template syntax / Functions / in instructions / ref

ref(...)Available from FirstSpirit Version 4.0

The ref(...) function provides the opportunity to directly apply methods to a medium or a page reference specified via the identifier. This is particularly useful if, e.g. a design element is to be manually specified in a page template.

Syntax of ref(...)

When using ref(...) the following syntax must be adhered to:

$CMS_VALUE(ref(IDENTIFIER,
abs: VALUE,
contentId:VALUE,
index:VALUE,
lang:"LANGUAGE ABBREVIATION",
language:"LANGUAGE ABBREVIATION",
postfix:IDENTIFIER,
remote:IDENTIFIER,
res:"RESOLUTION",
resolution:"RESOLUTION",
template:"IDENTIFIER",
templateSet:"CHANNEL NAME",
version:CHANNEL NUMBER
).METHOD)$

All parameters, apart from the IDENTIFIER are optional.

Parameters of ref(...)

ref(...) has the following parameters:

IDENTIFIER

Within ref(...) the reference name of an object is specified within FirstSpirit with the identifier.

If the object is specified manually the identifier consists of two parts:

  1. Object type
  2. Reference name of the object

The object type depends on the type of an object. The following object types exist:

  • File or picture from the Media Store: media
  • Page reference or document group from the Site Store: pageref
  • Menu level from the Site Store: pagefolder

If the URL of a picture from the Media Store with the reference name “suedsee” is to be determined, the following identifier must be given for ref(...):

media:"suedsee"

Use pageref to create a link to the specified page reference, for example

<a href="$CMS_VALUE(ref(pageref:"detail"))$">more...</a>

If the page reference specified by pageref is a content projection (page reference basing on a data section) so that more than one page will be rendered, by default the page with the dataset with the highest ID will always be returned. Also filters and sortings defined on the tab “Content” will be taken into account for determining the page or the dataset with the highest ID.

When using pagefolder, by default the start page reference on the highest level below the specified structure folder (menu level) will always be used.

Alternatively a variable name or even a system object can be specified, e.g. the current page (with #global.node). Method invocations can be applied to the objects.

abs

As a default the paths determined by ref(...) (.getUrl() method) depend on the project property Absolute links. If this property is enabled ref(...).getUrl() returns absolute path details (corresponds to abs:1). If the property is deactivated, it returns relative path details (corresponds to abs:0).

The optional parameter can be used to overwrite the project property for a ref(...) specification. The following specifications can be given:

Specification

Meaning

abs:0

Returns relative path details (= default).

abs:1

Returns absolute path details with prefix

abs:2

Returns absolute path details without prefix.

abs:3

Returns an internal URL for use in internal processors (e.g. creation of PDFs in FirstSpirit).
Important: The specification of abs:3 is only reasonable for media.

abs:4

Returns an external URL for use in external processors.
Important: The specification of abs:4 is only reasonable for media.

  

Absolute path details are always absolute to the root of the web application. In generation, this is the generation directory (e.g. FirstSpirit-Server/web/fs4staging/project_1234/2345).

To complete the URL of abs:1 the specification prefix for absolute paths is used in the schedule management. The given prefix (e.g. http://meinServer) is placed in front of the absolute path details.

Alternatively the prefix can also be specified in a template. To this end the $CMS_SET(...)$ must be used to set the value of the system object #global.urlCreator.urlPrefix accordingly:

$CMS_SET(#global.urlCreator.urlPrefix,"http://meinServer")$

This prefix is then used for all the following ref(...).getUrl() invocations.

contentId

The contentId parameter can be used to determine the reference object for the given dataset.

As a value the parameter contentId expects the ID of a dataset.

The object with the identifier given for ref(...) must be a content projection (page reference basing on a page with data section).

When the parameter contentId is to be reflected in the URL, the value on the tab “Content” of the content projection for “Number of entries per page” must be 1 (i.e. only one dataset will be represented on each page).

Example:

$CMS_VALUE(ref(pageref:"data_source", contentId:374).METHOD)$

In the example the page reference data_source is a content projection. Here the dataset with the ID 374 is to be taken into account to determine the reference object.

Important Using the parameter template the search for the dataset can be restricted to a special table template.

index

The index parameter can be used to determine a reference object for a specific sub-page, e.g. a content projection. As a value the parameter index expects the number of the required sub-page. The sub-page counting begins with 0.

Example:

$CMS_VALUE(ref(pageref:"data_source", index:3).METHOD)$

In the example the page reference data_source is a content projection. Here the 4th sub-page generated by the projection (index = 3) is to be taken into account to determine the reference object.

lang / language

When the optional attribute lang and/or language is specified the given project language is additionally taken into account in the determination of the reference object. If the parameter is not specified the current language (preview and generation) is used for the resolution.

Use of the parameter is useful for language-dependent pictures and files.

A language abbreviation (valid for the project) must be given in double inverted commas as the value for the attribute, (e.g. lang="DE").

$CMS_VALUE(ref(media:"suedsee", lang:"EN").METHOD)$

postfix

In the case of theme-based sub-areas of the Site or Media Store it sometimes happens that all objects of a sub-area contain the same suffix (e.g. _d).

An example of a theme-based area is a teaser picture, which is to look different depending on the menu item. The reference name for the picture for this purpose could contain the common name component “teaser” and have a different suffix for each menu item. In addition a “fallback picture” can be given, which does not contain a suffix.

The determination of a reference object for use of the option parameter postfix is as follows:

  1. First an attempt is made to find an object with the reference name and the given postfix (IDENTIFIER + postfix)
  2. If no object is found an attempt is made to find an object without the given postfix (IDENTIFIER)

Either a fixed value enclosed in inverted commas can be given for the parameter or alternatively a variable name (e.g. from the Site Store).

Example:

$CMS_VALUE(ref(media:"suedsee", postfix:"_A").METHOD)$

In this case an attempt is first made to find a picture or file in the Media Store with the reference name suedsee_A . If a picture or file is not found an attempt is made to determine a picture or a file with the reference name suedsee .

Important Numerical information should not be selected for the suffix (e.g. _1) as otherwise overlapping can occur with the automatic unification of reference names. E.g. if a page reference is created in the Site Store with the reference name meineReferenz and if a page reference with the same name already exists a suffix is appended to the reference name in the form _INTEGER.

remote

Using the parameter remote links pointing to Remote projects can be generated (information about how to configure Remote projects or Remote media see page Remote access or documentation about the functionality FirstSpirit Remote-Media).

Important A valid licence for the Remote media access is required to be able to use the parameter remote.

As a value the parameter expects the Symbolic name assigned in the configuration of the Remote project (in the project properties).

Example:

$CMS_VALUE(ref(pageref:"pagereference_test", remote:"remoteproject"))$

In this example the page reference with the UID pagereference_test from the Remote project with the Symbolic identifier remoteproject will be resolved.

References to Remote projects are output analogously to those to the current local project, for example:

<a href="$CMS_VALUE(ref(lt_reference_remote))$" title="$CMS_VALUE(lt_comment)$">$CMS_VALUE(lt_text)$</a>

In this example a link to the page reference selected by the input component lt_reference_remote will be generated. If the input component provides remote access (e.g. FS_REFERENCE with <PROJECTS> / <REMOTE>) and if the user selected a page reference of the remote project, this will simply be output by means of $CMS_VALUE(ref(lt_reference_remote))$. (See also Chapter Link templates.)

res / resolution

If, for the determination of the reference object from the Media Store a resolution other than the original resolution is to be used (resolution with the identifier ORIGINAL) the parameter res and/or resolution must be given.

A valid identifier of a resolution available in the project, enclosed in double inverted commas, is to be given as the parameter value (e.g. SCALED).

$CMS_VALUE(ref(media:"suedsee", res:"SCALED").METHOD)$

When using remote media projects:

Important Using the instruction $CMS_VALUE(ref(...))$ not only pictures from the same project (“target project”) can be referenced but also from remote projects. (In this case the attribute remote must be given.) When referencing pictures from remote projects it must be taken into account that remote and target projects can have different resolutions.

If the template developer specifies a special resolution by using res or resolution which does not exist in the remote project requesting a preview or generating can cause errors. The medium is displayed in the original resolution in this case.

If there are different resolutions in remote and target project with the same name (e.g. target project: resolution “thumbnail” with width 10 px, remote project: resolution “thumbnail” with width 50 px) only the resolutions of that project are evaluated the medium is selected from. If a picture from a remote Media Store is selected, only resolutions which have been configured for the remote project are used. If a picture from the locale Media Store is selected, the resolutions of the target project will be used.

Example:

  • the target project has got a resolution “thumbnail” (width 10 px)
  • the remote project A has got a resolution “thumbnail” (width 50 px)
  • the remote project B has got a resolution “thumbnail” (width 75 px)

In the target project then

  • a medium deriving from the locale Media Store of the target project with the resolution “thumbnail” will be displayed with a width of 10 px,
  • a medium deriving from the remote Media Store of remote project A with the resolution “thumbnail” will be displayed with a width of 50 px,
  • a medium deriving from the remote Media Store of remote project B with the resolution “thumbnail” will be displayed with a width of 75 px.

It is therefore advisable, when using remote projects, to define a specific resolution parameter res or resolution within templates if the resolution in target and remote projects are identical or if it is definitely sure which Media Store the selected media come from, e.g. if the selection has been restricted before by means of

...
<PROJECTS>
<REMOTE name="remoteproject">
<SOURCES>
<FOLDER name="root" store="mediastore"/>
</SOURCES>
</REMOTE>
</PROJECTS>
...

(see for example FS_REFERENCE).

Controlling automatically generated images in projects

Images can occur in different file types (such as JPEG) and resolutions in a project. Each image is initially stored unchanged in the project, i.e. in the format in which it was uploaded to the Media Store (resolution ORIGINAL).

Some actions trigger an automatic generation of new image files, based on the original image data, for example:

  • generating a preview image
  • creating new resolutions
  • using an automatically generated resolution
  • cropping an image in ContentCreator or in SiteArchitect

This generation process can be controlled via parameters.

Examples of use:

  • influencing the compression rate of JPG images in order to achieve increased image quality or reduced file size when generating images
  • preset the image type (e.g. WebP)

Project configuration

The calculation can be influenced with the custom ImageWriterParams project property.

Important Custom project properties (CUSTOM_PROPERTIES) can exclusively be added via the FirstSpirit Access-API (using setCustomProperties) and can not be defined with the FirstSpirit ServerManager (see Project interface in package: de.espirit.firstspirit.access.project, FirstSpirit Access API).

Beanshell example script for creating a new configuration:

project = context.getProject(); 
project.lock();
properties = new java.util.LinkedHashMap();
properties.put("thumbnail.jpg.compressionQuality", "0.75");
properties.put("default.jpg.compressionQuality", "0.75");
properties.put("resolution.HeaderPicture.jpg.compressionQuality", "0.95");
properties.put("resolution.HeaderPicture.png.compressionQuality", "0.95");
project.setCustomProperties("ImageWriteParam", properties);
project.save();
project.unlock();

The parameters should be passed via a LinkedHashMap.
The script must be executed with administrator permissions in the desired project.
The respective configuration is applied to all images from which corresponding resolutions are used.

Using the methods of the ImageWriteParam class
All methods of the ImageWriteParam class can be configured (see https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/ImageWriteParam.html). Since some methods depend on each other, the parameters should be added in the desired sequence.

resolution.<RESOLUTION_NAME>.<FILE_TYPE>.<SETTER_METHOD_NAME>

(with the keyword set being optional)

Preview images use thumbnail instead of resolution.<RESOLUTION_NAME>, as depicted in the example above.

The default value for compressionMode is MODE_EXPLICIT, but other values can be if desired.

Using the parameter targetType
Furthermore, the targetType parameter can be used. It can be used to specify the image format of automatically generated images.
Example script that creates all automatically generated image files in WebP format:

project = context.getProject();
project.lock();
properties = new java.util.LinkedHashMap();
properties.put("default.targetType", "webp");
project.setCustomProperties("ImageWriteParam", properties);
project.save();
project.unlock();

In addition, corresponding definitions can be defined for individual image formats and/or resolutions.
Here, the setting for the current specific image type is used. If not available, the global setting is used for the resolution and as a fallback.
Example script that keeps the type PNG for PNG images, uses the type JPG for the resolution “Icon” and applies the type WebP for all other scaled images:

project = context.getProject();
project.lock();
properties = new java.util.LinkedHashMap();
properties.put("default.targetType", "webp");
properties.put("default.png.targetType", "png");
properties.put("resolution.Icon.targetType", "jpg");
project.setCustomProperties("ImageWriteParam", properties);
project.save();
project.unlock();
Important Each image format has a specific ImageWriteParm implementation that may differ from other image formats in terms of possible parameters (the parameters are generically mapped to setter methods of ImageWriteParm) and behaviour.

Using the parameter discardMetadata

The project property ImageWriteParam can be used to discard metadata of the original image (e.g., EXIF information) when generating images. By default, these are taken over.

In the following example, the property is configured to discard metadata for all images expect for PNG files.

project = context.getProject(); 
project.lock();
properties = new java.util.LinkedHashMap();
properties.put("default.discardMetadata", "true");
properties.put("default.png.discardMetadata", "false");
project.setCustomProperties("ImageWriteParam", properties);
project.save();
project.unlock();

Reading out an existing configuration
Use the following method to read the current configuration:

context.project.getCustomProperties("ImageWriteParam");

If no configuration is set, the return value will be <null>.

Deleting / resetting an existing configuration
Overwriting an existing configuration with an empty configuration removes the existing configuration, e.g.

project = context.getProject();
project.lock();
properties = new java.util.LinkedHashMap();
project.setCustomProperties("ImageWriteParam", properties);
project.save();
project.unlock();

template

The parameter template provides the possibility to confine the parameter contentId and must be given together with this parameter. With template the search, accomplished by contentId, can be narrowed to a specific table template by specifying the UID of this table template, if e.g. two table templates represent the same dataset. The use of template is e.g. reasonable to link a dataset in a specific representation / layout, e.g. in a detailed view.

As a value the parameter template expects the UID of a table template.

The search is started in this case from a structure folder (object type pagefolder). Here, always the start page reference which lies on the highest level below the specified structure folder (menu level) will be returned. This start page reference must be a content projection if the definition of contentId is expected to have an impact.

If you would like another page reference than the start page reference to be respected you should use the parameter template.

Use the method .getUrl() for determining the URL to the dataset (as when using $CMS_REF(...)$).

Example:

$CMS_VALUE(ref(pagefolder:"root", contentId:322, template:"products.product_group".url))$

In this example a page of a content projection is searched for, beginning at the root node of the Site Store, which is rendering the dataset with the ID 322 on the basis of the table template products.product_group.

templateSet

If more than one template set is defined in a project it can be useful or required to determine a reference object to another template set.

The optional parameter templateSet can be used for this.

The value of templateSet must be specified as a valid identifier of a template set in the project, enclosed in double inverted commas.

version

The optional parameter version corresponds to the parameter templateSet, however the number of the template set is given as the value.

The template set numbering in a project begins with 0, i.e. the first template set has the number 0, the second has the number 1 etc.

Reference object

The ref(...) function returns a reference object which, depending on the reference type, makes available methods.

The following reference objects can be returned by the ref(...) function:

  • ContentProducerReference for page references
  • MediaReference for media

ContentProducerReference (Site Store)

The following methods can be applied to the ContentProducerReference reference object:

Method

Meaning

Return data type

ref(...).filename

Determines the file name

string

ref(...).page

Returns (if available) the referenced page from the Page Store.

Page

ref(...).target

Returns the actual element from the store, e.g. the page reference.

Element dependent, e.g.
PageRef

ref(...).url

returns the URL equivalent to the $CMS_REF(...)$ instruction.

string

   

Output of the file name:

$CMS_VALUE(ref(pageref:"unternehmen").filename)$

Output of the unique identification number of a page reference (PageRef):

$CMS_VALUE(ref(pageref:"unternehmen").target.id)$

MediaReference (Media Store)

The following methods can be applied to the MediaReference reference object:

Method

Description

Return data type

ref(...).crc

Returns the CRC value of the picture.

Long

ref(...).description

Returns the description of a picture.

string

ref(...).extension

Returns the extension of a picture.

string

ref(...).extension("RESOLUTION")

Returns the extension of a picture for the given resolution.

string

ref(...).height

Returns the height of a picture in pixels.
Note: .height can only be used for pictures.

Integer

ref(...).height("RESOLUTION")

Returns the height of a picture in pixels for the given resolution.
Note: .height(...) can only be used for pictures.

Integer

ref(...).size

Returns the file size of a picture.

Long

ref(...).size("RESOLUTION")

Returns the file size of a picture for the given resolution.

Long

ref(...).target

Returns the actual element from the store, e.g. the medium.

Element dependent, e.g.
Media

ref(...).url

Returns the URL equivalent to the $CMS_REF(...)$ instruction.

string

ref(...).width

Returns the width of a picture in pixels.
Note: .width can only be used for pictures.

Integer

ref(...).width("RESOLUTION")

Returns the width of a picture in pixels for the given resolution.
Note: .width(...) can only be used for pictures.

Integer

   

Output of the width:

$CMS_VALUE(ref(media:"suedsee").width)$

Output of the height:

$CMS_VALUE(ref(media:"suedsee").height)$

Output of the width for the resolution W100:

$CMS_VALUE(ref(media:"suedsee").width("W100"))$

Output of the height for the resolution H100:

$CMS_VALUE(ref(media:"suedsee").height("H100"))$

Output of the unique identification number of a page reference (Media):

$CMS_VALUE(ref(media:"suedsee").target.id)$

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