ref(...)
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
- abs
- contentId
- index
- lang / language
- postfix
- remote
- res / resolution
- template
- templateSet
- version
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:
- Object type
- 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 data record 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 data record 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). |
abs:4 | Returns an external URL for use in external processors. |
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 data record.
As a value the parameter contentId expects the ID of a data record.
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 data record 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 data record with the ID 374 is to be taken into account to determine the reference object.
Using the parameter template the search for the data record 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:
- First an attempt is made to find an object with the reference name and the given postfix (IDENTIFIER + postfix)
- 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 .
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).
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)$
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).
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 data record. The use of template is e.g. reasonable to link a data record 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 data record (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 data record with the ID 322 on the basis of the table template products.product_group.
templateSet
If more than one presentation channel is defined in a project it can be useful or required to determine a reference object to another presentation channel.
The optional parameter templateSet can be used for this.
The value of templateSet must be specified as a valid identifier of a presentation channel in the project, enclosed in double inverted commas.
version
The optional parameter version corresponds to the parameter templateSet, however the number of the presentation channel is given as the value.
The presentation channel numbering in a project begins with 0, i.e. the first presentation channel 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 | |
ref(...).page | Returns (if available) the referenced page from the Page Store. | |
ref(...).target | Returns the actual element from the store, e.g. the page reference. | Element dependent, e.g. |
ref(...).url | returns the URL equivalent to the $CMS_REF(...)$ instruction. | |
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. | |
ref(...).description | Returns the description of a picture. | |
ref(...).extension | Returns the extension of a picture. | |
ref(...).extension("RESOLUTION") | Returns the extension of a picture for the given resolution. | |
ref(...).height | Returns the height of a picture in pixels. | |
ref(...).height("RESOLUTION") | Returns the height of a picture in pixels for the given resolution. | |
ref(...).size | Returns the file size of a picture. | |
ref(...).size("RESOLUTION") | Returns the file size of a picture for the given resolution. | |
ref(...).target | Returns the actual element from the store, e.g. the medium. | Element dependent, e.g. |
ref(...).url | Returns the URL equivalent to the $CMS_REF(...)$ instruction. | |
ref(...).width | Returns the width of a picture in pixels. | |
ref(...).width("RESOLUTION") | Returns the width of a picture in pixels for the given resolution. | |
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)$