Including/injecting experience fragment component directly within the sightly. | Community
Skip to main content
kanishakar14249
September 27, 2018

Including/injecting experience fragment component directly within the sightly.

  • September 27, 2018
  • 3 replies
  • 5125 views

I have a requirement where I need to include the content fragment OOTB component directly within the sightly and map it to respecitive fragments within the component. Something like below :

<div data-sly-resource="${'tabMap{0}' @ format=tabMapList.count ,resourceType='/libs/cq/experience-fragments/components/experiencefragment'}"></div>

Above implementation is required within the tab component, so needs to be added within the list(loop).

I am able to see any other foundation/custom component appearing on the page but unable to add the experience fragment.

Am I missing something any further configuration or step to achieve the same?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

arunpatidar
Community Advisor
Community Advisor
September 27, 2018

Hi,

The correct location of component is /libs/cq/experience-fragments/editor/components/experiencefragment

But It is not working there also I can see errors in error.logs

TypeError: Cannot call method "get" of undefined (/libs/cq/experience-fragments/editor/components/experiencefragment/experiencefragment.js#22)

  at org.apache.sling.scripting.sightly.js.impl.loop.EventLoop.run(EventLoop.java:71)

  at org.apache.sling.scripting.sightly.js.impl.loop.EventLoop.schedule(EventLoop.java:46)

  at org.apache.sling.scripting.sightly.js.impl.JsEnvironment.runScript(JsEnvironment.java:106)

Arun Patidar
smacdonald2008
Level 10
September 27, 2018

I agree with Arun - its not working. Only way i have used an Experience Fragment in an HTL component is when it has this line:

<sly data-sly-resource="${'content-par' @ resourceType='wcm/foundation/components/parsys'}"/>

THen i drop the Experience Fragment into the HTL component.

smacdonald2008
Level 10
September 27, 2018

This works --

raj_mandalapu
Level 7
September 28, 2018

I think, the experience fragment will not work if it is not under the parsys node. you must dynamically find the parsys node and add child node as experience fragment node then it should work.

You need to write java code that finds out parsys and using addNode method add experience fragment node. then when you open tab component you will see experience fragment component.

Another approach is if the component is fixed on the template then you can add node hierarchy at template jcr:content node level.

raj_mandalapu
Level 7
September 28, 2018

kanishakar14249474,

If it is author driven then you will not have control on it,  you must write Java code, which finds par node and add experience fragment node as a child node, but think about tradeoff's