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

1k views Asked by At

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!

2

There are 2 answers

0
Glen Mazza On BEST ANSWER

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.

0
Tamas On

Glen: Thank you for the reply - it nicely summarize where I should be coming from to tackle this issues with URL in Roller.

Just to leave some constructive remarks here - for some reason (perhaps there is a ghost in my machine) but the Permalink does not work for me, however this does:

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

...and for Pages...

<a href="$url.page($model.weblogPage.link)">Permalink</a> 

...I have no idea why these work and why your example (which is shown in the original documentation too) do not.

I did not make any investigations on creating URL at category browsing or search function but I guess it will follow similar pattern.

Anyway, thank you for the help, am all good now!