January 2, 2021
Estimated Post Reading Time ~

Hiding Granite UI Resource Dynamically

Granite UI offers two ways of hiding the resource dynamically.
  • FilteringResourceWrapper (granite:hide)
  • RenderCondition (granite:rendercondition)
UseCase: To hide/filter a resource from being rendered based on some custom conditions.

Understanding the differences in terms of usage:
granite:hide
granite:rendercondition
Decision making logic/condition is defined using Expression Language(EL).

Decision-making logic/condition is defined in a component ie. A separate rendercondition component will hold the logic.
Supported Variables/functions in EL (for Granite UI resource) are available hereOOB rendercondition components are available here
The custom variables can also be registered using ExpressionCustomizer. One such variable is cqDesign for fetching the design properties as we would do with currrentDesign global object.
(OOB core components uses this variable in EL- ${cqDesign.customproperty})
Custom rendercondition components can be created based on our requirements.
Usage: Property named "granite:hide" is to be created with the value being EL on the resource to be filteredNode named "granite:rendercondition" or "rendercondition" is to be created under the resource to be filtered.
Properties for this node being "sling:resourceType" with the value as rendercondition component or custom component's path
Ex: Widely used in OOB core components to control dialog fields based on design/policy configuration of that component.
The condition can be controlled at the property level itself making use of the cqDesign custom variable. Hence EL is preferred in this case.
Ex: In Page selection -> action bar -> Create -> Workflow option will be available/should be rendered for those who have access to /etc/workflow/models.
This condition has to be implemented by making use of AccessControlManager API on a specific path. Hence rendercondition is preferred for this use case.

A specific example on each of these is to be covered in a separate post for better clarity.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.