How to force an editor to contribute at least one element in an jnt:area ?
Question
Sometimes you want to make sure that editors do not leave an area (which is stored as a jnt:contentList
) completely empty. For example, a homepage might require at least one teaser, or a blog section might require at least one article. A common question is therefore: Can Jahia force editors to contribute at least one element inside an area?
The short answer is: No, Jahia does not provide a native way to enforce this constraint.
However, you can guide editors by displaying a clear message in Edit mode when a list is empty, so they understand that content is expected.
Answer
By design, Jahia does not prevent saving or publishing empty lists.
If a jnt:contentList
(or any area) has no sub-nodes, the system considers it valid.
The solution is to implement a UX-friendly helper:
- Create a custom list type (a subtype of
jnt:contentList
), - Use it in your templates where you want to avoid empty lists,
- Provide a footer view that displays a message only when the list is empty in Edit mode.
This way, editors are gently reminded to add content, without blocking their work.
Example implementation
- Declare a mixin subtype
[jmix:nonEmptyList] > jnt:contentList
- Use it in a template
When you declare an<template:area>
in a template, you can specify anareaType
.
• By default, if noareaType
is provided, the area is created as ajnt:contentList
, which is Jahia’s built-in node type for storing lists of child nodes.
• TheareaType
parameter allows you to override this default and tell Jahia to use a different node type for the underlying list.<template:area path="teaser" areaAsSubNode="true" areaType="jmix:nonEmptyList"/>
Here, instead of creating a plain
jnt:contentList
, the area is created as ajmix:nonEmptyList
(which itself extendsjnt:contentList
). -
Create a footer override
For your custom list type, you only need to provide thehidden.footer
view — all other views are automatically inherited fromjnt:contentList
.
This means you don’t need to duplicate or redefine standard views likelist.jsp
, only the one that contains your extra logic.
Create the filesrc/main/resources/jmix_nonEmptyList/html/nonEmptyList.hidden.footer.jsp
<c:if test="${renderContext.editMode and currentNode.isNodeType('jmix:nonEmptyList') and empty moduleMap.currentList}"> <div class="alert alert-info" role="status"> This list can’t be empty — please add at least one item to continue! </div> </c:if>
Because
jmix:nonEmptyList
extendsjnt:contentList
, all default rendering (like list display in Live or Preview) is preserved — only the footer in Edit mode is customized.
Result
- In Edit mode, editors see the message when the list is empty.
- In Live/Preview, nothing is displayed.
- This is guidance only, not a blocking validation.