Velocity and XSL parameters

From VYRE

Jump to: navigation, search

Th following are replaced as parameters in XSL and as velocity variables in static code portlets, and the name, title and header fields for pages.

NOTE: Velocity variables do not work in Page Templates. You need to use the JSP equivalent in order to get those values within a JSP.

Contents

Path related

  • $context_path : the context path of the current web application. Since the backend and delivery applications have different context paths, it is necessary to prefix links to pages or "other files" with this variable. Note that all file paths that you get from the XML already include the context path. Context path equates to "/vyre4" when in the backend.
  • $current_path : the path to the current page including the context path.
  • $page_path : the path of the current page, without the context path.
  • $parent_path : the path to the parent of the current page (if the page has a parent).
  • $item_path : the "item${itemId}/" string for the current item on an item display page (empty string if no item selected).
  • $page_path_from_left / $page_path_from_right : arrays of the page paths from left and right where $page_path_from_right.get(n) will return the page path specified or #foreach ($page in $page_path_from_right ) $page #end will return all the page paths (not in XSL).
  • $full_path_from_left / $full_path_from_right : arrays of the full paths to pages from left and right where $full_path_from_right.get(n) will return the full path to the page specified or #foreach ($page in $full_path_from_right ) $page #end will return all the full paths to each page (not in XSL).
  • $last_get_url: the path of the last GET url (with the context path). This is retrievable in PortalAttributes / xsl / velocity. This functionality was introduced in Unify 4.6. If you are using a previous version this feature will not be available.
  • $unify_version: will return only the current version of the system (if it is a snapshot, it should include the snapshot number) This functionality was introduced in Unify 4.6.2. If you are using a previous version this feature will not be available.

Portlet related

  • $portlet_id : id of the currently edited portlet

Localised Path Variables

The following localised variables offer the same functionality as above but use the localised version of the path (as of 4.4.0.2)

  • $localised_current_path
  • $localised_parent_path
  • $localised_page_path_from_left
  • $localised_page_path_from_right
  • $localised_full_path_from_left
  • $localised_full_path_from_right

Item related

  • $current_store_id : the ID of the store of the current display item.
  • $current_item_id or $item_id : the ID of the current display item.
  • $item_name : name of current display item.
  • $item_description : description of current display item.
  • $item_keywords : keywords of current display item.
  • $item_version : version of current display item.
  • $item_locale : locale of current display item (since 4.7).
  • $item_creation_date : creation date of current display item.
  • $item_modification_date : last modification date of current display item.
  • $item_content_store_id : ID of the store of the current display item.
  • $item_content_store_name : name of the store of the current display item.
  • $item_att123: where 123 is the ID of the attribute we want to display.

Page related (since 4.3)

  • $page_id : the ID of current page, or empty string if on a template
  • $page_name : the name of the current page
  • $page_description : the description of the current page
  • $site_id : the ID of current site, or empty string if on a template
  • $site_title : the title of the current site
  • $site_description : the description of current site
  • $site_url : the domain name of current site

Current User related

  • $current_user_id : the ID of the current user
  • $current_user_username : the username of the current user
  • $current_user_email : the email address of the current user
  • $current_user_fullname : the full name of the current user
  • $current_user_creation_date : the date the current user's profile was created
  • $current_user_modification_date : the date the current user's profile was last modified
  • $current_user_last_login_date : the last date the current user signed in
  • $current_user_profile_id : the profile ID of the user which is logged in
  • $current_user_group_ids : a comma separated string containing the IDs of groups which the user is member of (since 4.3)
  • $current_user_profile_group_ids : a comma separated string containing the IDs of profile groups which the user is member of (since 4.3)
  • $current_user_{property name} : note that '.' and '-' has been replaced with '_' in the {property name}
  • $current_user_group_names
  • $current_user_profile_group_names

For example to access the current user's first name you would use $current_user_user_name_given

User related

These variables will only available in user portlets, not the static code portlet or user edit custom code.

  • $user_username
  • $user_password
  • $user_fullname
  • $user_email
  • $user_creation_date
  • $user_modification_date
  • $user_last_login_date
  • $user_{property name}
  • $user_profile_id - refers to profile id of this user, since Unify 4.7

Locale related

  • $siteLanguage : the language of the current site
  • $renderLocale : the locale of the current page
  • $bundle.translate('my.localization.key') : the contents of a localization key (not in XSL, there is a different syntax for using localization keys in XSL).

Date related

  • $current_day : the current day (1-31)
  • $current_month : the current month (1-12)
  • $current_year : the current year (four digits)
  • $current_date_and_time : the current date and time on this format: dd.MM.yyyy HH:mm

Render attributes (since 4.4)

Request parameters (since 4.4)

XSL include (since 4.4)

  • $xslPath : Path of XSLs stored in the 'include template' folder.
<xsl:include href = "$xslPath/x11.xsl"/>

Velocity Statements

A velocity statement can be constructed to add more flexibility to the inclusion of these variables.

For example: The following statement can be used for an Item Edit page that is used to both create and edit items, if the page is viewed to edit an existing item then it will include the name of that item in the Title - if, however, the page is used to create a new item, and the $item_name variable would not exist, then it is replaced by the page Name ($page_name)

$site_title - #if($item_name) $item_name #else $page_name #end

Please note if correct spacing matters, you can use {} (curly brackets) around velocity reserved words (this will correctly index your field and search / sorting will work as expected). For more information read http://velocity.apache.org/engine/devel/user-guide.html#Conditionals .We would write the above example as:

$site_title - #{if}($item_name)$item_name#{else}$page_name#{end}

Another use is functions such as substring(), which can be used in the following code below to generate a welcome message which changes based on time:

#if($current_date_and_time.substring(11,13) < 12) Good Morning #elseif($current_date_and_time.substring(11,13) < 18) Good Afternoon #else Good Evening #end

A third use is when attempting to use a page name containing a localisation key in a template or static text portlet. As it isn't parsed twice the key itself will be returned. To get around this the use the following code:

$bundle.translate($page_name.substring(19,$page_name.lastIndexOf("'")))

For more information, please see the Velocity User Guide

Cached XSL (since 4.3)

XSL caching has been introduced into Unify 4.3, this option can be selected from the Publishing Components branch of the System Configuration Module. XSL caching will considerably improve performance of your site and is recommended for all installations running 4.3.

However, if XSL caching is enabled then any velocity variables that you wish to use will have to be declared as XSL variables. This is done by calling the variable as an XSL parameter before you use it:

For example: To use the $context_path variable you must first declare it as:

<xsl:param name="context_path"/>

If you want to use it in a test you will use:

<xsl:if test="$context_path = 'vyre4'"></xsl:if>

You can then print out the variable as an XSL variable using either of the following: Directly on the page using a the xsl:value-of tag:

<xsl:value-of select="$context_path"/>

Or by using braces surrounding the variable within an attribute of HTML tag (eg: <a> or <img> tag as part of a url path):

<img src="{$context_path}/other_files/my_image.gif" />


Using velocity variables in other languages

jsp

you can have examples in the jsp code page.

or here:

 <c:when test="${param.linkId != null}">

javascript

the easiest one:

document.location.href="$context_path/path/to/your/item/edit/item$item_id"

See Also

External Links

Personal tools