Apache Sling HTL Blog Sample

This module is part of the Apache Sling project.


This sample is designed as an introduction to Sling and HTL.


  • Create, update, delete posts with featured images.
  • List posts, read posts.



1. Run Sling

java -jar org.apache.sling.launchpad-9.jar

2. Install HTLBlog

mvn clean install -PautoInstallBundle

3. Explore


Parts of the Application


HTL Blog uses Sling Models extensively. You can read about them here.

  • Author.java - This model detects if our user is logged in or not.
  • Edit.java - This is used to get a query parameter from our request, find the resource associated with the param, and adapt it to our post model.
  • List.java - This is used to iterate through our posts, reverse their order, and adapt them to our post model.
  • Post.java - This model injects our post properties, finds the featured image, and lists any children (comments).

Apps (HTL)

  • Admin
    • Page - The base admin page.
    • List - Based on Page. Used to list posts.
    • Edit - Based on Page. Used to create and edit posts.
  • Public
    • Page - The base public page.
    • List - Based on Page. Used to publicly list posts.
    • Post - Based on Page. Used to view an individual post.
  • Clientlibs
    • Mostly Bootstrap and some basic custom styles.


The content is built using a two JSON files under /content/htlblog. They map to the following nodes:

  • /content/htlblog/admin - Our admin home. Used to list our posts for editing or deleting.
  • /content/htlblog/admin/edit - Our edit page. Use to create, or if a post path is supplied, it will edit an existing post.
  • /content/htlblog/posts - Another post list, but also used as the parent of our posts.
  • /content/htlblog/posts/hello-world - Used to scaffold a placeholder post.
  • /content/htlblog/posts/hola-mundo - Used to scaffold a 2nd placeholder post.

Additional Reading

  • The SlingPostServet and Sling CRUD docs. Everything in this sample uses these concepts extensively.
  • The HTL Specification. If you have a question about HTL, it will likely be answered here. Note: The spec and the current release in Sling can be out of sync.
  • Sling Content Loading - Understand how to create initial content and map resourceTypes.