Liferay DXP FreeMarker Macros

Liferay DXP defines several macros in FTL_Liferay.ftl template that you can use in your theme templates to include theme resources, standard portlets, and more. Liferay DXP also exposes its taglibs as FreeMarker macros. See each taglib’s documentation for more information on using the taglib in your FreeMarker templates. This reference guide lists the available FreeMarker macros that Liferay DXP offers.

MacroParametersDescriptionExample
breadcrumbsdefault_preferencesAdds the Breadcrumbs portlet with optional preferences<@liferay.breadcrumbs />
control_menuN/AAdds the Control Menu portlet<@liferay.control_menu />
cssfile_nameAdds an external stylesheet with the specified file name location<@liferay.css file_name="${css_folder}/mycss.css"/>
dateformatPrints the date in the current locale with the given format<@liferay.date format="/yyyy/MM/dd/HH/" />
jsfile_nameAdds an external JavaScript file with the specified file name source<@liferay.js file_name="${javascript_folder}/myJs.js"/>
languagekeyPrints the specified language key in the current locale<@liferay.language key="last-modified" />
language_formatarguments
key
Formats the given language key with the specified arguments. For example, passing go-to-x as the key and Mars as the arguments prints Go to Mars.<@liferay.language_format arguments="${site_name}" key="go-to-x" />
languagesdefault_preferencesAdds the Languages portlet with optional preferences<@liferay.languages />
navigation_menudefault_preferences
instance_id
Adds the Navigation Menu portlet with optional preferences and instance ID.<@liferay.navigation_menu />
searchdefault_preferencesAdds the Search portlet with optional preferences<@liferay.search />
search_bardefault_preferencesAdds the Search Bar portlet with optional preferences<@liferay.search_bar />
user_personal_barN/AAdds the User Personal Bar portlet<@liferay.user_personal_bar />

A few reference examples are shown below.

Reference Examples

The example below includes a language key with the language macro directive along with its language key parameter:

<@liferay.language key="powered-by" />

This example includes the Search portlet with its Portlet Decorator portlet preference set to barebone:

<@liferay.search default_preferences=
  freeMarkerPortletPreferences.getPreferences(
    "portletSetupPortletDecoratorId", "barebone"
  ) 
/>

You can also pass multiple portlet preferences in an object, as shown in the example below for the Navigation Menu portlet:

<#assign secondaryNavigationPreferencesMap = 
  {
    "displayStyle": "ddmTemplate_NAVBAR-BLANK-JUSTIFIED-FTL", 
    "portletSetupPortletDecoratorId": "barebone", 
    "rootLayoutType": "relative", 
    "siteNavigationMenuId": "0", 
    "siteNavigationMenuType": "1"
  } 
/>

<@liferay.navigation_menu
  default_preferences=
  freeMarkerPortletPreferences.getPreferences(secondaryNavigationPreferencesMap)
  instance_id="main_navigation_menu"
/>
« Introduction to Front-End ReferenceFront-End Taglibs »
Was this article helpful?
0 out of 0 found this helpful