Sightly - Include another HTML and pass parameters

Avatar

Avatar

ashtrick

Avatar

ashtrick

ashtrick

15-10-2015

Hi smiley

I'm wondering if this is possible?

I have a component (xcomponent) and have the two sightly templates in this as follows

  1. xcomponent.html
  2. y.html

​I'm using JAVA-USE API to get the data for the template and including the y.html in xcomponent.html as below

<div data-sly-use.componentService="XComponentProxy" data-sly-test="${componentService}" data-sly-unwrap=""> <div data-sly-test.componentData="${componentService.componentData}" data-sly-unwrap=""> <!-- Template HTML goes here --> <!-- Template HTML goes here --> <!-- Template HTML goes here --> <div data-sly-include="y.html" data-sly-unwrap="${!(wcmmode.edit || wcmmode.design)}"></div> </div> </div>

Can someone please help me on how to pass the parameters from xcomponent.html to y.html so that I can use componentData created in xcomponent in y.html?

Thanks,

View Entire Topic

Avatar

Avatar

gabriel_walt

Employee

Avatar

gabriel_walt

Employee

gabriel_walt
Employee

15-10-2015

Got it! You're correct, each componentService.componentData.* variable access will call the getComponentData method.

Then I'd create another Java object to retrieve getComponentData, this will act like a cache for the current template:

public class Logic extends WCMUse { private ComponentData data; @Override public void activate() throws Exception { ComponentService s = new ComponentService(); data = s.getComponentData(); } public String getData() { return data; } }

If you have multiple templates all accessing the same service and data, and if getComponentData really is expensive, you could also easily cache it in a request attribute.