Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FreeMarker - Get Current URL

Tags:

freemarker

Is it possible to get the current page's URL in FTL?

like image 601
balexander Avatar asked Jul 08 '10 19:07

balexander


2 Answers

As far as I can tell, freemarker is strictly a templating engine -- it simply produces text, and has no way of knowing where that text will appear. If you want to include the "current page's URL", you'll either have to pass that data into the template from the host Java code (recommended) or you'll have to detect it client-side using javascript.

like image 80
Faisal Avatar answered Oct 23 '22 16:10

Faisal


I'm running Spring 3.2.x and exposeSpringMacroHelpers defaults to true.

As per Spring Documentation

Set whether to expose a RequestContext for use by Spring's macro library, under the name "springMacroRequestContext". Default is "true".

On my view, I can then do something like

<#if springMacroRequestContext.requestUri?contains("/login")>

Hope it helps.

like image 6
drmanalo Avatar answered Oct 23 '22 18:10

drmanalo