sling:resourceType and sling:resourceSuperType in AEM

sagar karotiasagar karotia
4 min read

In Adobe Experience Manager (AEM) and the underlying Apache Sling framework, sling:resourceType and sling:resourceSuperType are two fundamental JCR properties that dictate how resources (content nodes) are rendered and how components inherit behavior. While they sound similar, they serve distinct and crucial purposes.

Let's break down each:

1. sling:resourceType

  • What it is: This property is found on a content node (a JCR node representing actual content on a page, like a component instance). It points to the component that is responsible for rendering that content.1

  • Purpose: It tells Sling which script (HTL, JSP, etc.) should be executed to render the current content node. It's the direct link from a piece of content to its presentation logic.

  • Location: Typically found on content nodes within /content (e.g., a text component node under a page node).

    • Example: jcr:content/root/container/text_1 node might have sling:resourceType="wknd/components/content/text"
  • How Sling uses it: When Sling receives a request for a resource, it looks at the sling:resourceType property of that resource. It then searches for the corresponding component definition (usually under /apps or /libs) that matches this resourceType. Once found, it executes the rendering script (e.g., text.html for an HTL component) within that component's folder.

  • Mandatory: Every renderable content node must have a sling:resourceType defined, either explicitly on the node or implicitly inherited from its primary type (though explicit is common for components).

2. sling:resourceSuperType

  • What it is: This property is found on a component definition node (a JCR node defining the component itself, usually under /apps or /libs). It points to another component from which the current component should inherit rendering scripts and other properties.

  • Purpose: It enables component inheritance.2 Instead of duplicating rendering logic, a component can specify a sling:resourceSuperType to reuse the scripts of a "parent" or "base" component. If a script (e.g., dialog.xml, component.html) is not found in the current component's folder, Sling will look for it in the resourceSuperType component's folder, and then its resourceSuperType, and so on, up the inheritance chain.

  • Location: Typically found on component definition nodes within /apps or /libs (e.g., /apps/my-project/components/content/mycomponent/.content.xml).

    • Example: wknd/components/content/customtext component's .content.xml might have sling:resourceSuperType="wknd/components/content/text"
  • How Sling uses it: This property defines the search path for scripts. When Sling tries to resolve a script for a component (based on its sling:resourceType), it first looks in the component's own folder. If the script isn't found there, it then checks the component specified by sling:resourceSuperType, and so on. This creates a powerful inheritance hierarchy.

  • Optional: A component doesn't have to have a sling:resourceSuperType. If it doesn't, it's considered a "root" component in the inheritance chain.

Key Differences and Relationships:

Feature

sling:resourceType

sling:resourceSuperType

Applied to

Content Node (component instance)

Component Definition Node

Points to

The component to render the content

A parent component to inherit from

Role

Defines what to render

Defines how to find rendering logic (inheritance)

Cardinality

Mandatory for renderable content nodes

Optional for component definitions

Example Value

myproject/components/content/text

core/wcm/components/text/v2/text

Inheritance

Doesn't directly handle inheritance, but points to the component that might use inheritance.

Enables inheritance for component definitions.

Analogy:

Imagine a blueprint for a house (sling:resourceType) and a master architect's portfolio (sling:resourceSuperType).

  • When you want to build a house, you pick a specific blueprint (sling:resourceType). This blueprint tells the builders exactly how to construct that house.

  • But perhaps your blueprint for "Modern House" (myproject/components/content/modernhouse) is based on a "Basic House" blueprint from a master architect's portfolio (core/wcm/components/house). If your "Modern House" blueprint doesn't specify how to build the foundation, the builders will look at the "Basic House" blueprint for those instructions. This is sling:resourceSuperType in action.

Why are both important?

  • sling:resourceType ensures that every piece of content knows exactly which component should display it.

  • sling:resourceSuperType promotes code reuse, modularity, and maintainability. It's the backbone of AEM's component inheritance model, particularly evident with the AEM Core Components, where custom components often extend Core Components using sling:resourceSuperType to inherit their robust functionality and then override or extend specific parts.

0
Subscribe to my newsletter

Read articles from sagar karotia directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

sagar karotia
sagar karotia

I am a passionate frontend developer