how to pass handlebar attributes in data-sly-use | Community
Skip to main content
Level 2
June 20, 2023

how to pass handlebar attributes in data-sly-use

  • June 20, 2023
  • 1 reply
  • 1139 views

Hi All, 

 

We are calling WCMUsePojo (AbcDetails) and want to pass an attribute (part no) which are coming via handlebar, and somehow the attributes are not getting resolved. However, in data-sly-call we can pass the handlebar attributes. 

 

<sly
data-sly-use.abcDetails="${'com.abc.demo.AbcDetails' @partNo = '{{../partNo}}'}">
<sly
data-sly-use.testTemplate="components/content/test-template.html">
 
<sly
<!--  this works - IF we can get abcDetails by passing hardcoded partNo -->
data-sly-call="${testTemplate.demoOrder @abcInfo=abcDetails, definition='{{../../demo}}', parentIndex='{{../../test}}', info='{{../test1}}'}">
</sly>
</sly>
</sly>
 
Need urgent help, can we not pass handlebar attributes to data-sly-use
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Tanika02
Level 7
June 20, 2023

Hello @gunjan_13  - 

 

  • In HTL, you cannot directly pass handlebar attributes to data-sly-use directives. The data-sly-use directive expects a relative or absolute path to a Java class or a Use-API object reference.
  • However, you can achieve the desired functionality by passing the handlebar attributes to the data-sly-call block and then passing them as properties to the Use-API object within the Java class.

 

<sly data-sly-use.abcDetails="com.abc.demo.AbcDetails"> <sly data-sly-call="${testTemplate.demoOrder @abcInfo=abcDetails.getProperties(), partNo=partNo}"> </sly> </sly>

 

Gunjan_13Author
Level 2
June 20, 2023

Thank you @tanika02  for looking into it. 

The problem is I need to call the WCMUse and need to pass a value. And then I will get an object from the WCMUse, and later I need to call another sightly and pass that object and few more attributes. These attributes I am getting from handlebar and the below line works too (if I can get abcDetails anyhow)

 

data-sly-call="${testTemplate.demoOrder @abcInfo=abcDetails, definition='{{../../demo}}', parentIndex='{{../../test}}', info='{{../test1}}'}">

 

NOT WORKING -

data-sly-use.abcDetails="${'com.abc.demo.AbcDetails' @partNo = '{{../partNo}}'}">

 

partNo is going AS IS  ( '{{../partNo}}') to the WCMUse, I am not sure why it is not getting resolved. But, when I save the value to the workingPartNoworkingPartNo is getting printed correctly. 

<sly data-sly-test.workingPartNo ="{{../partNo}}">

 

workingPartNo - has the right value. 

 

ISSUE - How to pass workingPartNo to WCUSe and get the abcDetails.

krishna_sai
Community Advisor
Community Advisor
June 21, 2023

Hi @gunjan_13 , when you were able to print them correctly <sly data-sly-test.workingPartNo ="{{../partNo}}"> can you try sending saved workingPartNo instead of handlebar attribute directly like below

<data-sly-use.abcDetails="${'com.abc.demo.AbcDetails' @partNo = workingPartNo}">

 

I believe handlebar values are only accessible inside handlebar script tags.