You can make use of requestAttributes (refer here)
Component A (passing the value):
Sightly :
<sly data-sly-use.compA = "com.mysite.core.models.CompA"/>
<div
data-sly-resource="${ 'abc' @ resourceType = 'btplayer-cms/components/content/some-common-component', requestAttributes = compA.attribute }">
</div>
Sling Model :
package com.realogy.sir.core.models;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Model;
@Model(adaptables = SlingHttpServletRequest.class)
public class CompA {
public Map<String, Object> attribute = new HashMap<>();
@PostConstruct
protected void init() {
attribute.put("attributeVal", "componenta");
}
}
Component B (passing the value):
Sightly :
<sly data-sly-use.compB = "com.mysite.core.models.CompB"/>
<div
data-sly-resource="${ 'xyz' @ resourceType = 'btplayer-cms/components/content/some-common-component', requestAttributes = compB.attribute }">
</div>
Sling Model :
package com.realogy.sir.core.models;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Model;
@Model(adaptables = SlingHttpServletRequest.class)
public class CompB {
public Map<String, Object> attribute = new HashMap<>();
@PostConstruct
protected void init() {
attribute.put("attributeVal", "componentb");
}
}
Common Component (consuming the value):
Sightly :
<sly data-sly-use.commonComp= "com.mysite.core.models.CommonComp"/>
<div class="${[commonComp.attributeVal, 'button'] @ join='-'}"></div>
Sling Model:
package com.mysite.core.models;
import javax.inject.Inject;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Model;
@Model(adaptables = SlingHttpServletRequest.class)
public class CommonComp {
@Inject @Optional @Default(values="component")
private String attributeVal;
public String getAttributeVal() {
return attributeVal;
}
}