sling:include not working with selector | Community
Skip to main content
New Participant
June 29, 2016
Solved

sling:include not working with selector

  • June 29, 2016
  • 5 replies
  • 2751 views

I have a container component in container.jsp I want to include another component (Tile component) .Tile component has got 2 jsps,

In container.jsp when condition A matches I want to include Tile component only tile.jsp executed.

When condition B matches I want to include tile component only tile.selector.jsp to render content.

I tried with <cq:include resourceType="/apps/gwc/components/content/resTile" path ="abc.selector" />  

and <sling:include resourceType="/apps/gwc/components/content/resTile" path="abc" addSelectors="selector" />

Both dont work, every time I get tile.jsp rendered.

Thanks in advance.

Any help would be appreciated.

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

Got it working by doing the below mentioned.

The <cq:include> requires the path to actually exists in first place , does not craete a node with teh "path" under current content hierarchy, sling:include does that .

Below is the include statement that worked for me.

<sling:include resourceType="/apps/myapp/components/content/resTile" path="resTile_${count}" addSelectors="story" />

5 replies

asn11AuthorAccepted solution
New Participant
June 30, 2016

Got it working by doing the below mentioned.

The <cq:include> requires the path to actually exists in first place , does not craete a node with teh "path" under current content hierarchy, sling:include does that .

Below is the include statement that worked for me.

<sling:include resourceType="/apps/myapp/components/content/resTile" path="resTile_${count}" addSelectors="story" />

kautuk_sahni
Employee
June 30, 2016
kautuk_sahni
Employee
June 30, 2016

Hi

You could  use sling:include tag, which provides attributes to modify the selectors & suffix on the request:

<sling:include resourceType="myComponent" path="my/path" addSelectors="altView"/>

or

<sling:include resourceType="myComponent" path="my/path" replaceSelectors="altView"/>

Link:- http://stackoverflow.com/questions/23530232/how-to-properly-check-selectors-and-extensions-via-requestpathinfo

 

I hope this helps.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
Jitendra_S_Toma
New Participant
June 29, 2016

@Ann_177,

Just a thought.Have not tried but one way to soleve is to rely on path attribute in sling include rather than resourceType. Let's suppose you have component BOX, you want to include FEED component with multiple selectors then put the relative path with selectors.

for instance,

<sling:include path="/par/feed" addSelectors="json"/>

<sling:include path="/par/feed" addSelectors="xml"/>

Jitendra_S_Toma
New Participant
June 29, 2016

@Asn_177,

This is what sling document provide.

  • resourceType - The resource type of a resource to include. If the resource to be included is specified with the path attribute, which cannot be resolved to a resource, the tag may create a synthetic resource object out of the path and this resource type. If the resource type is set the path must be the exact path to a resource object. That is, adding parameters, selectors and extensions to the path is not supported if the resource type is set.

https://sling.apache.org/documentation/bundles/scripting/scripting-jsp.html#include

asn_177 wrote...

I have a container component in container.jsp I want to include another component (Tile component) .Tile component has got 2 jsps,

In container.jsp when condition A matches I want to include Tile component only tile.jsp executed.

When condition B matches I want to include tile component only tile.selector.jsp to render content.

I tried with <cq:include resourceType="/apps/gwc/components/content/resTile" path ="abc.selector" />  

and <sling:include resourceType="/apps/gwc/components/content/resTile" path="abc" addSelectors="selector" />

Both dont work, every time I get tile.jsp rendered.

Thanks in advance.

Any help would be appreciated.