How to remove the wrapping div when using data-sly-resource? | Community
Skip to main content
Level 2
May 18, 2016
Solved

How to remove the wrapping div when using data-sly-resource?

Hi all,

currently we have a setup that includes a page using the following snippet:

<sly data-sly-resource="${item.path @ selectors='link', wcmmode='disabled'}"></sly>

this results in

<div class="base-page case-detail-page page">        <a href="">Name</a> </div>

Is there a way to remove the div and just keep the a href?

Much appreciated!

Regards

 

Mario

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Feike_Visser1
Feike_Visser1Accepted solution
Employee
May 18, 2016

Ok..., here comes a black-magic Sightly trick....

Use this (resourceType) in case you are referring to a page...

  1. <sly data-sly-resource="${item.path @ selectors='link', wcmmode='disabled', appendPath='jcr:content',  resourceType=item.contentResource.resourceType}"></sly>

 

Basically to remove the div you need to specify the resourceType...

11 replies

Feike_Visser1
Employee
May 1, 2017

This only applies when you have a page you want to render via data-sly-resource

Translate
Level 3
May 1, 2017

Feike Visser wrote...

Ok..., here comes a black-magic Sightly trick....

Use this (resourceType) in case you are referring to a page...

  1. <sly data-sly-resource="${item.path @ selectors='link', wcmmode='disabled', appendPath='jcr:content',  resourceType=item.contentResource.resourceType}"></sly>

 

Basically to remove the div you need to specify the resourceType...

 

This is the most black-magic trick I have seen for sightly! :) I thought that providing resoureType won't affect rendering at all (just be nice way to render even if there is no node under certain path). Thanks for that info! 

Translate
Feike_Visser1
Employee
January 13, 2017

Do you have more details/info on your issue?

Translate
ashish_kumarm48
Level 2
January 12, 2017

Could you please provide the solution of the above problem?

I am also facing the same problem.

Translate
mario_vdeAuthor
Level 2
May 18, 2016

This solved it!

Thank you Feike.

Translate
Feike_Visser1
Feike_Visser1Accepted solution
Employee
May 18, 2016

Ok..., here comes a black-magic Sightly trick....

Use this (resourceType) in case you are referring to a page...

  1. <sly data-sly-resource="${item.path @ selectors='link', wcmmode='disabled', appendPath='jcr:content',  resourceType=item.contentResource.resourceType}"></sly>

 

Basically to remove the div you need to specify the resourceType...

Translate
mario_vdeAuthor
Level 2
May 18, 2016

Hi Feike,

yes, it's a page.

So we have the base-page component. And this component has a link.html.html selector with this as its content:

<sly data-sly-use.basePage="${'be.idamediafoundry.foundation.component.page.BasePage'}" data-sly-unwrap> <a href="${basePage.uri}.html">${basePage.title}</a> </sly>

So when including this page, with the "link"-selector, we want to get the a tag, without the wrapping div because it's meaningless. 

thanks Feike.

Translate
Feike_Visser1
Employee
May 18, 2016

hi mario,

Is this a item.path a page?

--
Feike

Translate
mario_vdeAuthor
Level 2
May 18, 2016

Hi,

Yes I am fully aware of that, but we include the output of a rendered page. And aem automagically wraps it in a div.

This is the page that gets includes (using selectors)

<div data-sly-use.basePage="${'be.foundation.component.page.BasePage'}" data-sly-unwrap>
       <a href="${basePage.uri}.html">${basePage.title}</a>
</div>

so the unwrap is on there, but the output is still wrong.

Thanks for the quick reply!

Translate