Adrien Be Adrien Be - 4 months ago 37
Java Question

Check if Node exists for given UUID


(See my update below for a simple solution using standard Magnolia directives)

How about using the search searchfn

or QueryUtil

and searching by UUID:

SELECT * FROM [nt:base] WHERE [jcr:uuid] = '7fd401be-cada-4634-93fa-88069f46297b'

Using it in Freemarker:

You can wrap every Java function, such as search, in a custom freemarker directive.


In your module xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module SYSTEM "module.dtd" >
... calls the QueryUtil standard class - or SessionUtil such as:


public class MyTemplatingFunctions {
    public boolean doesNodeExist(String workspace, String id){
        if ( SessionUtil.getNodeByIdentifier(workspace, id) != null ){
            return true;
        return false;

Then in your .ftl:

[#-- @ftlvariable name="myfn" type="" --]
${myfn.doesNodeExist(relevantWorkspace, someUUID)}

== Update ==

Just checking the Magnolia docs:

Does this not work?

[#assign myAsset = damfn.getAsset("jcr:20d6e4e3-fe53-4b23-8d64-6e67a1c1667f")!]

where you can then check with if / else in Freemarker for myAsset?

This would look like the simplest solution. Haven't tested it but it looks as if it should be possible to pass the UUID together with the jcr: prefix.

Furthermore: if you don't need to explicitly check if the asset exists, but just don't want to get a template error in the log, you can add a ! like this:


then you don't get a template error, just a WARN message in the log.