Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

sling:include not working with selector

Avatar

Level 5

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.

1 Accepted Solution

Avatar

Correct answer by
Level 5

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" />

View solution in original post

5 Replies

Avatar

Level 9

@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.

 

Avatar

Level 9

@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"/>

Avatar

Administrator

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-reque...

 

I hope this helps.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Correct answer by
Level 5

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" />