Skip to content

Instantly share code, notes, and snippets.

@byterider
Forked from gabrielwalt/_nodes.txt
Created April 3, 2020 15:24
Show Gist options
  • Save byterider/fa44cfff6f6b21ade4e8124892b418ed to your computer and use it in GitHub Desktop.
Save byterider/fa44cfff6f6b21ade4e8124892b418ed to your computer and use it in GitHub Desktop.
Passing request attributes with Sightly
/content
/example
@jcr:primaryType = "nt:unstructured"
@jcr:title = "Outer Component"
@sling:resourceType = "example/components/outer"
/one
@jcr:primaryType = "nt:unstructured"
@jcr:title = "Inner Component One"
@sling:resourceType = "example/components/inner"
/two
@jcr:primaryType = "nt:unstructured"
@jcr:title = "Inner Component Two"
@sling:resourceType = "example/components/inner"
/apps
/example
/components
/inner
@jcr:primaryType = "cq:Component"
/inner.html
/inner.js
/outer
@jcr:primaryType = "cq:Component"
/outer.html
/outer.js
<div class="outer">
<h1>Outer Component</h1>
<ul>
<li>
<div class="inner">
<h2>Inner Component One</h2>
<p>Hello World!</p>
</div>
</li>
<li>
<div class="inner">
<h2>Inner Component Two</h2>
</div>
</li>
</ul>
</div>
<div class="inner" data-sly-use.logic="inner.js">
<h2>${properties.jcr:title}</h2>
<p data-sly-test="${logic.attributes.foo}">
${logic.attributes.foo}
</p>
</div>
use(function () {
return {
attributes: request.getAttribute(resource.getPath())
};
});
<div class="outer" data-sly-use.logic="outer.js">
<h1>${properties.jcr:title}</h1>
<ul data-sly-list="${resource.listChildren}">
<li data-sly-resource="${item.name}"></li>
</ul>
</div>
use(function () {
request.setAttribute(resource.getPath() + "/one", {
foo: "Hello World!"
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment