Magnolia CMS: Getting node/page/paragraph IDs and user details using JSP

Just a quick note to remind me, and let anyone else who tries to do this know, how to access the unique id (uuid) of a page or paragraph, and details about the current user in a JSP page in Magnolia CMS. We are watching to save, via AJAX, information about how students use pages and paragraphs (in particular self-test question paragraphs) within our Magnolia installation, and need these details in order to do this.

Displaying the node/page/paragraph ID

If you put this code in a page template, it will show you the unique ID for the page. If you put it in a paragraph template it will show you the unique id for that paragraph. These IDs do not change when you move a page, or a paragraph within a page.

<cms:out nodeDataName="uuid" var="uuid" />
<p>${uuid}</p>

Displaying the name of the current user

<jsp:scriptlet>
   String user = (info.magnolia.context.MgnlContext.getUser().getName()).toString();
   out.println("&lt;p&gt;" + user + "&lt;/p&gt;");
</jsp:scriptlet>

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.