Liferay Default Theme Velocity Variables

Liferay Default Theme Velocity Variables tutorail will show light on the available velocity variables in Liferay theme. As you already know, Liferay already set parent variables in  init.vm (/liferay-home/tomca/webapps/ROOT/html/themes/unstyled-theme/templates/init.vm).

Liferay  VelocityTemplateContextHelper.java(\portal-impl\src\com\liferay\portal\velocity\VelocityTemplateContextHelper.java) is used to initialize all variables in Liferay 6+versions. In Liferay5 below, VelocityVariables.java used to objects.

 velocityContext.put("arrayUtil", ArrayUtil_IW.getInstance());
 // Browser sniffer
 velocityContext.put(
 "browserSniffer", BrowserSnifferUtil.getBrowserSniffer());
 // Date formats
 velocityContext.put("dateFormats", DateFormats_IW.getInstance());
 // Date tool
 velocityContext.put("dateTool", new DateTool());
 // Date util
 velocityContext.put("dateUtil", DateUtil_IW.getInstance());
 // Escape tool
 velocityContext.put("escapeTool", new EscapeTool());

List of velocity variables in theme template:

 

  • $theme_display
  • $portlet_display
  • $request
  • $css_folder       — -$theme_display.getPathThemeCss()
  • $images_folder —  $theme_display.getPathThemeImages()
  • $javascript_folder –$theme_display.getPathThemeJavaScript()
  • $templates_folder — $theme_display.getPathThemeTemplates()
  • $full_css_path
  • $company
  • $layout  –  Current layout
  • $user
  • $full_templates_path
  • $is_signed_in  — $theme_display.isSignedIn()
  • $current_time
  • $the_year
  • $permissionChecker.isOmniadmin() –> to check Super Admin

 

  • $dateUtil
  • $escapeTool
  • $propsUtil  -> To get Portal Ext Properties ($propsUtil.get(“propertye-key”))
  • $paramUtil
  • $getterUtil
  • $htmlUtil
  • $portalUtil
  • $portal
  • $prefsPropsUtil
  • $propsUtil
  • $portletURLFactory   ->    Here is sample code to create Portlet URL’s in Velocity templates.
    • #set($test_plid = $portalUtil.getPlidFromPortletId($theme_display.getScopeGroupId(), false, “test_WAR_testportlet”))
    • #set ($test_url = $portletURLFactory.create($request, “test_WAR_testportlet”, $test_plid, “RENDER_PHASE”))
      $test_url.setWindowState(“normal”)
      $test_url.setPortletMode(“view”)
      $test_url.setParameter(“privateLayout”, “false”)
      $test_url.setParameter(“cmd”, “basicView”)
  • $stringUtil
  • $unicodeFormatter
  • $validator
  • $arrayUtil
  • $browserSniffer
  • $dateFormats
  • $dateTool
  • $dateUtil
  • $escapeTool
  • $expandoColumnLocalService
  • $expandoRowLocalService
  • $expandoTableLocalService
  • $expandoValueLocalService
  • $httpUtil
  • $imageToken
  • $iteratorTool
  • $languageUtil
  • $unicodeLanguageUtil
  • $localeUtil
  • $randomizer
  • $serviceLocator
  • $sessionClicks
  • $staticFieldGetter
  • $listTool
  • $mathTool
  • $sortTool
  • $numberTool

Useful code snippets in Liferay theme Velocity templates:

  • Theme. Runtime is used to insert portlet at theme level
    • $theme.runtime(“emailnotification_WAR_kpiemailnotificationportlet_INSTANCE_adfckdkkek”)
  • to check Omni admin
    • #if ($is_signed_in && $permissionChecker.isOmniadmin())
      #dockbar()
      #end
  • To get the cotent based on locale:
    • $languageUtil.get($locale, $the_title, $page.getName($locale))

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *