Macros
can assign theme template fragments to a variable. This keeps your theme
templates from becoming cluttered and makes them easier to read. Liferay DXP
defines several macros in
FTL_Liferay.ftl
template
that you can use in your FreeMarker theme templates to include theme resources,
standard portlets, and more. Liferay DXP also exposes its taglibs as FreeMarker
macros. See the corresponding
taglib tutorial
for more information on using the taglib in your FreeMarker templates. This
tutorial shows how to use macros in your FreeMarker theme templates.
Follow these steps:
-
Select one of the macros shown in the table below:
Macro Parameters Description Example breadcrumbs default_preferences Adds the Breadcrumbs portlet with optional preferences <@liferay.breadcrumbs />
control_menu N/A Adds the Control Menu portlet <@liferay.control_menu />
css file_name Adds an external stylesheet with the specified file name location <@liferay.css file_name="${css_folder}/mycss.css"/>
date format Prints the date in the current locale with the given format <@liferay.date format="/yyyy/MM/dd/HH/" />
js file_name Adds an external JavaScript file with the specified file name source <@liferay.js file_name="${javascript_folder}/myJs.js"/>
language key Prints the specified language key in the current locale <@liferay.language key="last-modified" />
language_format arguments
keyFormats the given language key with the specified arguments. For example, passing go-to-x
as the key andMars
as the arguments prints Go to Mars.<@liferay.language_format arguments="${site_name}" key="go-to-x" />
languages default_preferences Adds the Languages portlet with optional preferences <@liferay.languages />
navigation_menu default_preferences
instance_idAdds the Navigation Menu portlet with optional preferences and instance ID. <@liferay.navigation_menu />
search default_preferences Adds the Search portlet with optional preferences <@liferay.search />
search_bar default_preferences Adds the Search Bar portlet with optional preferences <@liferay.search_bar />
user_personal_bar N/A Adds the User Personal Bar portlet <@liferay.user_personal_bar />
-
Call the macro in your theme template. Liferay DXP’s default FreeMarker macro calls are namespaced with
liferay
. For example, to include the Search Bar portlet, you would add the macro call shown below:<@liferay.search_bar>
-
Include any required or optional arguments, such as portlet preferences, in the macro call. For example, Liferay DXP’s
language
macro directive includes a language key parameter:<#macro language key > ${languageUtil.get(locale, key)} </#macro>
You can pass an argument in the macro call like this:
<@liferay.language key="powered-by" />
The example below sets the Search portlet’s Portlet Decorator 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" />
Now you know how to use Liferay DXP’s macros in your theme templates!