Expand my Community achievements bar.

Data-sly-resource not working for composite components

Avatar

Level 3

UPDATE: I have a Composite component A, which have a child B (also a composite component) . B has a cq:template  which initializes children of B lets say title, name and image components.  I am trying to call B in A -n numbers of time since its a multifield, therefore I cant intialize B along with its children in A's cq:template.

 

This doesnt works as expected in sightly, I am not able to get children of B title, name and image in A.

 

6 Replies

Avatar

Community Advisor

Hi @troubleshooter3 ,

May I have the screen shot of node structure?. Also, where are you including the "data-sly-resource"? is it in that same template html?.


Thank you.

 

Avatar

Level 3

@B_Sravan  I have a component called as X which is a composite component created using components A and B( is also a composite component created using 3 other components). Now I am trying to create a new component Y that will use component X. All looks good I am able to call X from Y but unable to initialize component B, component A looks good.

Avatar

Community Advisor

Hi,

You need to add the defualt values of children componnet in the container/parent component's cq:template with the content node structure.

e.g. container/parent component's cq:template

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:primaryType="nt:unstructured"
    variant="two">
    <child1
            jcr:primaryType="nt:unstructured"
            sling:resourceType="myapp/components/content/custom-column"
            columnLayout="l-grid__column-large-4 l-grid__column-medium-6"/>
     <child2
            jcr:primaryType="nt:unstructured"
            sling:resourceType="myapp/components/content/custom-column"
            columnLayout="l-grid__column-large-4 l-grid__column-medium-6"/>
</jcr:root>


Arun Patidar

Avatar

Level 3

 @arunpatidar I am not sure if I can do that, because child components are like my slides (multiFieldModels), they can be 100,200 or anything. I cant initialize that much code in parents cq:template. I need a way to programmatically initialize grand children in my component.

Avatar

Community Advisor

hi,

Is it ok to set value property to the child component's field. This will intialize the component with default value but values will not be saved until you hit save/submit to the dialog.



Arun Patidar

Avatar

Level 3

@arunpatidar To initialize I am looking for grand children nodes under child nodes and not the properties. Setting up all this from cq:template will be a lot since we dont know how many nodes we need