Reputation: 41
Is it possible for header-portlet-javascript to pick up from system properties?
For example:
<header-portlet-javascript>${external.js.url}</header-portlet-javascript>
Upvotes: 4
Views: 519
Reputation: 1402
In general, this is not possible.
However, if it's ok that the Javascript you want to include occurs on every page of your portal, you could just add a reference to it inside your Liferay theme. Inside the theme, you can do dynamic stuff to retrieve the right JS url, e.g. using a portal property:
#set($jsUrl = $propsUtil.get("external.js.url"))
<script type="text/javascript" src="$jsUrl"></script>
To have the same effect with System properties, things get a bit more complex. To my knowledge there is no way to get System properties from an injected Velocity variable. Therefore, we need to create a small event handler hook that will inject this property into the Velocity context.
servlet.service.events.pre=my.custom.ServicePreAction
public class ServicePreAction extends Action {
public void run(HttpServletRequest request, HttpServletResponse response) {
Map<String,Object> veloVars = new HashMap<String,Object>();
veloVars.put("externalJSurl", System.getProperty("external.js.url"));
request.setAttribute(WebKeys.VM_VARIABLES, veloVars);
}
}
<script type="text/javascript" src="$externalJSurl"></script>
Upvotes: 1