Search code examples
aemsightly

How to set variable from use object in sightly?


I have plain use class which contains one method that returns complex bean with a lot of setters/getters. Lets name it SomeUse. Given sightly file:

<sly data-sly-use.someUse="com.mycompany.SomeUse">
  ${someUse.data.firstProperty}
  <div>
    ${someUse.data.secondProperty}
  </div>
  <!-- ...and so on -->
</sly>

So the point is I don't want to look at someUse.data getting. Instead of it I would do something like this:

<sly data-sly-use.someUse="com.mycompany.SomeUse" data-sly-use.data=${someUse.data}>
  ${data.firstProperty}
  <div>
    ${data.secondProperty}
  </div>
  <!-- ...and so on -->
</sly>

I can't do this way though. Is there any alternative to achieve such result? Thanks a lot!


Solution

  • So the answer is to:

    <sly data-sly-test.varName="${data.firstProperty}"></sly>
    <div> ${varName.secondProperty} </div>
    

    Creating a variable through empty data-sly-test attribute make it accessible after a tag.