Tuesday 13 June 2017

extraClientlibs in AEM

To define styling and behavior of our AEM components, we create client libraries that defines our custom CSS and JS. In order to create clientlibs that load only in the Authoring mode, the general practice is to create a client library and load that only in the Author mode:

<sly data-sly-test.author="${wcmmode.edit || wcmmode.design}" 
data-sly-call="${clientlib.js @categories='custom.authorjs'}" /> </sly>

Further, if we want our client library loaded for all dialogs, we can set the category property to 'cq.authoring.dialog'. This would let the client library load for all dialogs.

This created performance issues sometimes when my client library is too big and I try loading it in all dialogs even when it is not needed. Sometimes, I would just want to have my client library only for a specific component's dialog.

To have my client library loaded solely for my component dialog, I need to the set the property 'extraClientLibs' of my dialog to the category name of the client library.

Here is an example:



Hope this helps!



Wednesday 7 June 2017

Sling Pipes

Ever encountered a situation where code changes were introduced after the client started authoring and some pages had to be re-authored? Ever spent time writing code just to modify a few hundred pages that were already authored, or with removing a component from hundreds of authored pages? Have you struggled to modify content already in the repository? Need a script to change existing production content? Sling Pipes to the rescue.
Sling Pipes is a tool for doing extract – transform – load operations through a resource tree configuration. This tiny toolset provides the ability to do such transformations with proven and reusable blocks, called pipes, streaming resources from one to the other.
A pipe is a JCR node with:
  • sling:resourceType property – Must be a pipe type registered by the plumber
  • name property – Used in bindings as an id
  • path property – Defines pipe’s input
  • expr property – Expression through which the pipe will execute
  • additionalBinding node – Node you can add to set “global” bindings (property=value) in pipe execution
  • additionalScripts – Multivalue property to declare scripts that can be reused in expressions
  • conf child node – Contains addition configuration of the pipe

Registered Pipes:

Container Pipes
Pipe
Description
sling:resourceType
Container Pipe
assemble a sequence of pipes
slingPipes/container
ReferencePipe
execute the pipe referenced in path property
slingPipes/reference

Reader Pipes
Pipe
Description
sling:resourceType
Base Pipe
outputs what is in input
slingPipes/base
SlingQuery Pipe
executes $(getInput()).children(expression)
slingPipes/slingQuery
JsonPipe
feeds bindings with remote json
slingPipes/json
MultiPropertyPipe
iterates through values of input multi value property and write them to bindings
slingPipes/multiProperty
XPathPipe
retrieve resources resulting of an xpath query
slingPipes/xpath
AuthorizablePipe
retrieve authorizable resource corresponding to the id passed in expression
slingPipes/authorizable
ParentPipe
outputs the parent resource of input resource
slingPipes/parent
FilterPipe
outputs the input resource if its matches its configuration
slingPipes/filter

Writer Pipes
Pipe
Description
sling:resourceType
Write Pipe
writes given nodes & properties to current input
slingPipes/write
MovePipe
JCR move of current input to target path (can be a node or a property)
slingPipes/mv
RemovePipe
removes the input resource
slingPipes/rm
PathPipe
get or create path given in expression
slingPipes/path

Here is a demo video with more on how to use and execute sling pipes in AEM.

Vid
More details can be found in the official documentation at https://sling.apache.org/documentation/bundles/sling-pipes.html