UTIL library

The UTIL library is a library built and hosted by Enonic, which includes a set of utility functions which may speed up the module development process significantly.
The UTIL library should normally be included in your build step (automatically downloaded upon module build) if you intend to use it as-is, or you can download the source on Github.

Include this in your build.gradle file to automatically download it in your module build:

repositories {
    maven {
        url 'http://repo.enonic.net/public'

dependencies {
    include 'com.enonic.lib:util:0.0.3'

More info coming soon


I have a proposal for a new utility function. How many times do you get a content and then have to get a related content? This function will get a content and then take a given related content reference and get that content too and add it to the first returned content. Let’s say you want to get a “profile” content. If the profile has a related “department” content, then all you get is the id for the department. But if you want to show the name of the department on a profile-show page, then you have to do another content.get(). Now you would simply use:
UTIL.content.getWithRefs(profileKey, {department: ‘departmentContent’})

Now the object returned is the exact same as it would be with content.get(), but it also has a new data element named departmentContent which holds the department content.

This only works when you know there can only be one related content, though it could be modified. I was also thinking of simply replacing the related id with the content instead of leaving the original reference.

1 Like

Thanks, I will have a look at this.

Also check my pull request on GitHub when you have time. I exposed the getSubMenu function in UTIL.menu because that is extremely valuable when building more than one menu on a site. I Hacked that into the UTIL files now for my current project, so can’t use gradles auto include for util lib.

@bwe You can override auto included files.

1 Like

Moved to the “Modules” category.

I propose a change to the content.getPath(id); function. We made this function while working on enonic.com. I think there was a form and we wanted to save the created content in a specified folder if the part was configured, or else save the content under the page where the form was. But while working on other modules, I didn’t want it to work that way. I set a module configuration to be the default, but the local part config could override that. I needed getPath() to return null if the id was null. The gist below shows a modified getPath() function that has an optional second parameter that (when “true”) tells the function to return null if the id is null or the content doesn’t exist.

By the way, the difference between id, path and key is that “key” could be either id or path. You wouldn’t pass a “path” to a getPath function.

The original getPath is on top and the one I’m proposing is on the bottom. It’s backward compatible so it won’t break any existing code that uses it.

Is it an idea to create tags in the sourcecode on github corresponding to the released gradle versions?


I am in the process of writing some guidelines when it comes to changelog and versioning of every Enonic owned project. Stay tuned :smile:


Version 1.0.0 of the util lib has now been published (for XP 6.0), and is available as a dependency in Gradle, and on Github (see first post in this thread).

Some of the old functionality in Util has been moved into separate libs (menu and image)

1 Like

What’s The link to this project?

Missing some documentation/api - maybe a simple version can be in The readme.md

1 Like