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.

Contents

[edit] 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.
  • $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).

[edit] 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_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 (not in static code): where 123 is the ID of the attribute we want to display

[edit] 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


[edit] 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}

[edit] User related

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

  • $user_username
  • $user_fullname
  • $user_email
  • $user_creation_date
  • $user_modification_date
  • $user_last_login_date
  • $user_{property name}

[edit] 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).

[edit] Date related (since 4.3)

  • $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

[edit] 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

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 at http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html

[edit] 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"/>

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

[edit] See Also

[edit] External Links

Personal tools