Menu
Showing posts with label snippets. Show all posts
Showing posts with label snippets. Show all posts
Saturday, 22 July 2017
Sunday, 28 August 2016
AEM Code Snippets
// to get list of selectors in an array
String[] selectors = slingRequest.getRequestPathInfo().getSelectors();
// to get a page from a path
Page page = pageManager.getPage(path);
// to get any containing page for a resource
Page page = pageManager.getContainingPage(resourceResolver.getResource(path));
// to get a session in JSP
final SlingRepository repos = sling.getService(SlingRepository.class);
session = repos.loginAdministrative(null);
// to get query object and run a query
//build query using search in crx explorer or crxdelite
String stmt = "select * from cq:Page where jcr:path like '/content/training/%' and contains(*, '" + slingRequest.getParameter("q") + "') order by jcr:score desc";
Thursday, 11 August 2016
HTL (Sightly) Code Snippets
Below are few HTL syntax used frequently in AEM.
1. HTL does not support JSP tag libraries.
2. Including a script: data-sly-include instead of cq:include
<cq:include script="template.html"/> //Including a HTL file in JSP
<sly data-sly-include="template.jsp"/> //Including a JSP file in HTL
The element on which a data-sly-include has been set is ignored and not displayed.
<sly data-sly-include="template.jsp"/> //Including a JSP file in HTL
The element on which a data-sly-include has been set is ignored and not displayed.
3. Including a Resource: data-sly-resource
Includes the result of rendering the indicated resource through the sling resolution and rendering process. Basic syntax-
<article data-sly-resource="path/to/resource"></article>
Override resourceType of an include-
<article data-sly-resource="${'path/to/resource' @ resourceType='my/resource/type'}"></article>
Change the wcmmode-
<article data-sly-resource="${'path/to/resource' @ wcmmode='disabled'}"></article>
Subscribe to:
Posts
(
Atom
)