Wednesday, 7 February 2018

HTL Basic Examples

Global Objects
  • page 
  • currentPage
  • properties
  • inheritedPageProperties
  • currentDesign
  • currentSession
  • wcmmode
Refer for list of global objects


Converting JSP Method into HTL

  • JSPcurrentPage.getContentResource()).getResourceType()
Remove() from JSP methods

  • HTL 1 :  ${currentPage.getContentResource.getResourceType}
OR Simply Remove get from method name
  • HTL2${currentPage.contentResource.resourceType}


HTL Examples

Get title of page using HTL

  • ${page.title}
Get any custom property from page using HTL
  • ${page.getProperties['root/responsivegrid/content/customPropertyName']
Handling Property Array using HTL
<div data-sly-list = "${currentPage.getProperties['component/reference']}"> 
${item}
</div>

( reference is property name , component is component node under jcr:content)


Get date using HTL
  • ${ 'dd-MMMM-yyyy hh:mm:ss' @
           format=currentPage.lastModified,

           timezone='IST',

           locale='en'}



Get logged in user using HTL

  •  ${currentSession.userID} 
Get design path using HTL
  • ${currentDesign.path}
Check wcmmode using HTL
  • ${wcmmode.edit}







Basic Sling Model Exporter

/* Open a page which is having component /apps/project/components/page/page /content/project/en/jcr:content.model.json Don't miss...