Search code examples
urlvelocityapache-roller

Apache Roller - how to get absolute URL with path of a current page via Velocity template


I just couldn't find the way how to get the complete URL of a current page via Velocity template language of Apache Roller.

So far I tried:

  • $url.absoluteSite - this gives the TLD of the site, but no path.
  • $url.site - gives me nothing (probably due to the Tomcat's virtual host set-up)

I tried some other combinations of various methods given by the Roller Template guide, but none of them yield any results.

I am not sure if Roller comes with Velocity tool installed, I tried some examples from StackOverflow, related to LinkTool but it seemed that it doesn't work.

Well, this is it in short - all I need is a line of Velocity code that gets the current full URL in Roller.

Thanks a lot folks!


Solution

  • Sure, Roller incorporates Velocity, including generic macros that you might be able to leverage. Also, just by opening a pre-packaged theme you can see how Roller uses Velocity to generate many of its URLs. For example, the home page of the Roller blog is

    $url.home
    

    the permalink of any given blog entry is

    <a href="$url.entry($entry.anchor)">Permalink</a> 
    

    and its comment page is:

    <a href="$url.comments($entry.anchor)">Comments</a>
    

    The above captures most of the pages that Roller generates, perhaps taking care of your needs. I'm unsure whether you'll be able to find a generic macro for the URL that any arbitrary page will render as, because that's primarily a function of how your templates are written, not the macros that being used on those templates.