Dealing with content

Even though our page is very simple and contains a static text, the Web page we created has already some few properties!

In this simple example, we will now use the Magnolia core tag library to display the content of the title property.

A list of available tags is available on the reference page. Here we will use the cms:out tag, which is probably the most useful tag; this is done in two steps:

  • Include the Magnolia core tag library with the JSP directive "taglib".
  • Use the tag itself. cms:out to display content element ("nodeData").
If you reopen the JSP script you previously created, adapt it as follows:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="cms-taglib" prefix="cms" %>
<html>
  <head>
    <title><cms:out nodeDataName="title" /></title>
  </head>
  <body>
    <h1><cms:out nodeDataName="title" /></h1>
    <p>Hello Magnolia World !</p>
  </body>
</html>

Web page Refresh your "Hello World" Web page and note that the window title has changed. It will show the title of the Web page. If you have created additional Web pages with the new template you will notice that when requesting these pages the window title changes dynamically, i.e. they will show the title that was assigned to them. And if you modify the title of one of these in the website workspace, you will noticed that refreshing them will also update their title.

Using the JCR Browser to visualize Content Nodes

Now, it might be useful to understand where this property is coming from. Pages (and nodes in general) can have an arbitrary number of properties, and it can sometimes be useful to have a look at them, if only to understand the structure of your pages.

The JCR Browser Tool Initially the JCR Browser may seem a little complicated, but once you know what you can use it for it will be very helpful. The JCR Browser lists all nodes (pages or "Content" objects) and properties ("NodeData" objects) created in the website workspace. This lets you see properties and paragraphs added to a page, for instance.

For now let's check how our new "Hello Page" is stored in the repository: open the "Tools" menu in the navigation pane and click on the "JCR Browser (Website)" item.

A list of nodes and properties in the website repository You will notice that our previously created page, "Hello World" (/hw) has one attached property: title, although our template does not yet deal with content elements (properties).

The title property has been added when we created the new page. It actually corresponds to the title column from the website workspace. If you create additional pages based on the new template, you will notice that they will all have a title property.