templates definitions jsp hidden Developer Jahia 8

How to define an unlisted type of content

Question

How to define an unlisted type of content and how to create such a content?

Occasionally, you need to define components that are not listed in the list of usable components. As an example, you could imagine a way to add some text on the bottom of the footer as a copyright, but you don't want this component to be available or used anywhere else. 

Answer

Here is a way to do it:

First, define the component that you want to have:

[jnt:copyright] > jnt:content, mix:title
- jcr:title (string) = 'Copyright Your Website 2022' internationalized

Then define a list for this type of component.

[jnt:copyrightList] > jnt:contentList, jmix:hiddenType
+* (jnt:copyright)

In these definitions, you can observe 2 things:

  • the jnt:copyright is not droppable content, so you can't use it from anywhere
  • the jnt:copyrightList inherit from the jmix:hiddenType so this content list won't be listed

As is, we cannot create any jnt:copyright on our page.
To be able to instantiate a copyright text, you can add the following line in your JSP template:

<template:area path="copyright" areaAsSubNode="true" 
    nodeTypes="jnt:copyright" areaType="jnt:copyrightList"/>

This will declare a copyright list that should only display a jnt:copyright content.
Better, and for a typical optional copyright text, you could limit the number of items to 1 and set the list as an absolute area, so the same content will be displayed on all pages.

<template:area path="copyright" areaAsSubNode="true" 
    nodeTypes="jnt:copyright" areaType="jnt:copyrightList" 
    level="0" moduleType="absoluteArea" listLimit="1"/>