Get endpoint url in freemarker
Hi Guys,
We have multiple environments running, all with a different URL..
On all the environments, we use a custom endpoint.. They are the same (code is just copied to other environment), but the URL is different in environments, but we cannot get the 'absolute' url to the endpoint in an easy way.. So we have to do ugly if/else statements to change the url..
Example:
If we call the endpoint:
in env A: /etgtr99956/plugins/custom/kpn/kpnbus/post-message
in env B: /kpn/plugins/custom/kpn/kpn/post-message
The first diff (etgtr99956, kpn) is easy to fix, because thats just the ${community.id},
but the second (kpnbus, kpn) is no logic difference, so it cannot be filled up easily with an existing variable..
Thus we have to do ugly if/else statements, like this ->
<#if community.id == 'etgtr99956'> <#assign url = ' /etgtr99956/plugins/custom/kpn/kpnbus/post-message' /> <#elseif community.id == 'kpn' && env == stage> <#assign url = '/kpn/plugins/custom/kpn/kpn/post-message' /> <#else> <#assign url = '/kpn/plugins/custom/kpn/kpnbus/post-message' /> </#if>
So point is:
Is there an easy way to get the absolute url to the endpoint from within freemarker?
Thanks!
You can use the community.urls.communityPrefix freemarker call (see the documentation on the commuinty freemarker context object) to get the the community id (it renders as '/' + ${communityid}, so if you community id is etgtr99956 then this will return as /etgtr99956).
Another thing to note is that your communities all have an apache rewrite rule in them that rewrites /plugins/... to /${communityid}/plugins/...
That doesn't really help with the second variable. For that I would recommend creating a variable or function in a macro that you include in all of your components and endpoints that can be used in constructing every endpoint url.
-Doug