Monday, April 30, 2012

Liferay Web Content Tokens

I did not know that even without all the fancy macro/template/velocity stuff that Liferay Journals/Web Content can do, there is the ability to still insert some dynamic content based on stuff like the j2ee context root.

Examples (for mostly unmodified liferay 6.1 guest community content with liferay still deployed to /ROOT):
@cdn_host@:
@company_id@: 10153
@friendly_url_current@: /web
@friendly_url_private_group@: /group
@friendly_url_private_user@: /user
@friendly_url_public@: /web
@group_friendly_url@: /guest
@group_id@: 10179
@image_path@: /image
@layout_set_friendly_url@: /web/guest
@main_path@: /c
@portal_ctx@:
@portal_url@: 127.0.0.1:8080
@protocol@: http
@root_path@:
@theme_image_path@: /my-custom-theme/images

Deprecated tokens

@friendly_url@: /web
@friendly_url_private@: /group
@page_url@: /web

I grabbed the list of tokens from JournalUtil.java instead of the wiki page.

On a side note, you still can't use the Liferay IDE with a non-ROOT j2ee context root yet.

1 comment:

Yaniv Rabl said...

You can also add in portal-ext.properties:
#
# Set a list of custom tokens that will be replaced when article content is
# rendered. For example, if set to "custom_token_1", then "@custom_token_1@"
# will be replaced with its token value before an article is displayed.
#

journal.article.custom.tokens=portal_friendly_url,portal_help_page
journal.article.custom.token.value[portal_friendly_url]=http://www.example.com
journal.article.custom.token.value[portal_help_page]=/web/guest/help

­
and in the template use:
@portal_friendly_url@
@portal_help_page@