Function to return directory path?

In one of our templates we need to output the full directory path to a file but not include the actual filename itself. $rx.location.generate() gives us the full path including the filename. Something like this:

$rx.location.generate($sys.assemblyItem, "[template]")

This produces something like:


It seems like Java would certainly have something to handle this. Perhaps this is even an available function in Velocity or as part of the Percussion API. Does anyone know a function we can use to just return the directory path without the filename, given output like that produced by $rx.location.generate()?

Unfortunately not knowing what functions/methods are available in which context is a major stumbling block for our development efforts. Using “debug” when previewing pages has helped but does not appear to be comprehensive. This difficulty is primarly due to being new to Java and unaware of where the documentation covers how Java/Velocity/Percussion API fits together and how we can use these when writing code for our templates. Does anyone know where the documentation outlines how all this ties together in CM System? Is there perhaps a tutorial which covers this topic?

We’ve had similar difficulty finding information on what system variables, etc. are available in what context. In asking technical support and also the consultant who helped us with our initial implementation work, we were told there basically is no single reference which outlines all the variables and describes them in detail. Instead it appears as though this information is sprinkled throughout the documentation instead of being consolidated into a comprehensive reference. To be sure, there is a significant number of documentation resources from the Java and Percussion API pages to the wiki and PDFs to the class materials, but we’ve yet to find something that ties these things together (Java functions/methods, Velocity, available variables, etc.) and describes how we can find whatever we need to deal with each coding situation we face. Without an understanding in this area it is quite hard to be self reliant and must instead post these which we’d prefer to not take up time on the forum if we knew how to find these simple answers ourselves.

Without digging through documentation to see if there is an actual function, you could just use java string manipulation to get the last ‘/’ and then just take the substring upto the position of the last slash…

If you have the PSO Toolkit (which is a free addon you can get from Percussion) installed, you can use the getParentFolderPath function, e.g.:
#set ($folderpath = $user.psoFolders.getParentFolderPath($sys.assemblyItem)). This should return you just the folder path, but not the filename. I would recommend installing this if you haven’t already, it’s very useful.

If you don’t have the PSO toolkit installed, you can use use $rx.location.generate and just strip off the filename part using some of the functions available in the Java String class. If you don’t have Java experience, you’re at a bit of a disadvantage in this product, to your point of not knowing what functions available to you. At the end of the day, Velocity is Java-based, so many of the functions you will able to use are just facades to Java classes, so often I just try calling functions in the same way I would in Java and often times it works. The only documeavailable from Percussion in this area is in the Workbench help, but it really just scratches the surface. Much the knowledge I’ve gained has some from looking in this forum, working with Percussion support to solve problems, and good old experimentation.