Sling Resource Merging Properties

In the realm of AEM developers have a powerful tool at their disposal that allows for seamless customization—Sling Resource Merging. This feature might sound a bit technical, but fear not! In this article, we’ll break down the key aspects of Sling Resource Merging and delve into its properties, showing you how they can simplify your development process.


1. A Deeper Look at Sling Resource Merging

Sling Resource Merging is like a code-friendly puzzle solver—it lets you combine resources and properties from different locations without getting tangled up. This is especially handy when you’re looking to make specific changes without messing around in the core functionalities stored in `/libs`. Let’s dive into the properties that make this process smoother.


2. Demystifying Sling Resource Merging Properties

Here’s a rundown of the essential properties you’ll encounter:


2.1. sling:hideProperties (String or String[])

This property allows you to hide certain properties that you don’t want to see. Whether you specify a single property or an array of properties, they’ll vanish from sight. The wildcard `*` works like magic—it hides everything except what you choose; Specifies the property, or list of properties, to hide.The wildcard * hides all.

Example:

1
2
3
4
5
6
7
8
<linkAriaLabel
    jcr:primaryType="nt:unstructured"
    sling:hideProperties="[linkAriaLabel]"
    sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
    fieldDescription="This aria label will be used for the link."
    fieldLabel="Link Aria Label"
    emptyText="Link Aria Label"
    name="./linkAriaLabel"/>

2.2. sling:hideResource (Boolean)

When set to `true`, this property hides a resource entirely, including its children. Think of it as a way to temporarily pull a curtain over a specific resource when you need it out of sight; Indicates whether the resources should be completely hidden, including its children.

Example: In this example, we are hiding linkAriaLabel from being rendered on the view.

1
2
3
4
5
6
7
8
<linkAriaLabel
    jcr:primaryType="nt:unstructured"
    sling:hideResource="{Boolean}true"
    sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
    fieldDescription="This aria label will be used for the link."
    fieldLabel="Link Aria Label"
    emptyText="Link Aria Label"
    name="./linkAriaLabel"/>

2.3. sling:hideChildren (String or String[])

Unlike the previous property, this one selectively hides child nodes while preserving their properties. Whether you’re hiding one or using `*` to hide them all, the properties stay untouched; Contains the child node, or list of child nodes, to hide. The properties of the node will be maintained. The wildcard * hides all.

Example: In this example, all children Granite UI fields are hidden from the view.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<fixedcolums
    jcr:primaryType="nt:unstructured"
    sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
    <items jcr:primaryType="nt:unstructured"
        sling:hideChildren="*">
        <properties
            jcr:primaryType="nt:unstructured"
            sling:resourceType="granite/ui/components/coral/foundation/container">
            <items jcr:primaryType="nt:unstructured">
                <pageTitle
                    jcr:primaryType="nt:unstructured"
                    sling:resourceType="granite/ui/components/coral/foundation/form/text"
                    ../>
                <description
                    jcr:primaryType="nt:unstructured"
                    sling:resourceType="granite/ui/components/coral/foundation/form/text"
                    ../>
            </items>
        </properties>
    </items>
</fixedcolums>

2.4. sling:orderBefore (String)

This property will force the Granite UI to render before a specific element. In this example, we are forcing the linkAriaLabel to render before the “title” Granite UI; Contains the name of the sibling node that the current node should be positioned in front of.

Example:

1
2
3
4
5
6
7
8
9
10
<title
     ..../>
<linkAriaLabel
    jcr:primaryType="nt:unstructured"
    sling:orderBefore="title"
    sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
    fieldDescription="This aria label will be used for the link."
    fieldLabel="Link Aria Label"
    emptyText="Link Aria Label"
    name="./linkAriaLabel"/>

3. Real-world Applications of These Properties

Let’s translate these properties into practical scenarios:

  1. Tailored Component Styling: Say you have a core component in `/libs` with default styles. Use `sling:hideProperties` to conceal unnecessary styles and introduce your own in `/apps`. This way, you retain the core functionality while customizing the look.
  2. Conditional Rendering: For situations where you need to show or hide an entire component, `sling:hideResource` is your ally. It’s like having a switch to control whether a component and its children should be displayed based on specific conditions.
  3. Optimized Content Arrangement: Use `sling:orderBefore` to reposition components within a container. This property is particularly helpful for responsive designs, ensuring content displays flawlessly on various devices.

4. Wrapping Up

Sling Resource Merging isn’t a mysterious incantation—it’s a tool that simplifies your AEM development journey. By getting acquainted with properties like `sling:hideProperties`, `sling:hideResource`, `sling:hideChildren`, and `sling:orderBefore`, you’re equipped to wield customization powers without the fuss. So go ahead, explore, and let Sling Resource Merging elevate your AEM development game!


Hello, I am an enthusiastic Adobe Community Advisor and a seasoned Lead AEM Developer. I am currently serving as an AEM Technical Lead at MNPDigital.ca, bringing over a decade of extensive web engineering experience and more than eight years of practical AEM experience to the table. My goal is to give back to the AEM Full Stack Development community by sharing my wealth of knowledge with others. You can connect with me on LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back To Top