How to use data-sly-use in SPA React for content fragments? | Community
Skip to main content
sesmic
Level 4
August 31, 2024
Question

How to use data-sly-use in SPA React for content fragments?

  • August 31, 2024
  • 2 replies
  • 802 views

Hi all,

We are working on custom SPA component which is supposed to take the given content fragment & use its field on page. 

In sites custom component we achieved this simply by using below snippet in html & it works fine. cfPath is content fragment path selected in component dialog's pathbrowser field.

<sly data-sly-test.cfPath="${'{0}/jcr:content/data/master' @ format=properties.cfPath}"
data-sly-use.cf="${cfPath}">
<p>${cf.fieldFromCF}</p>
<sly>

So, can anyone please help me to achieve the above in SPA react?

Any hint on this would be helpful.

Thanks,

sesmic

2 replies

kaikubad
Community Advisor
Community Advisor
September 1, 2024

on spa there is not need of data sly use. Because front end is not Sightly there. 

On SPA you send all the props to react/angular side. And based on the props show hide logics are on angular/react.

Generally on spa we expose all the props to react or call a servlet for backend data

sesmic
sesmicAuthor
Level 4
September 3, 2024

Hi @kaikubad,

Yes, I agree with you. But how can I implement it SPA?

In my SPA component how could I get the field values from CF.

kautuk_sahni
Community Manager
Community Manager
April 1, 2025

@sesmic Did you find the suggestion helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!

Kautuk Sahni