Having trouble with <@ofbizUrl>


#1

So, I was able to assign a FTL variable for the images

<#assign smallImageUrl = escapeVal(productContentWrapper.get(“SMALL_IMAGE_URL”,“url”) !, ‘htmlmarkup’, {“allow”:“internal”})/>

Returns: “/images/products/10000/1001MINIGOLF/small.jpg”, which is great. But what I’m looking for is the full path, like:

https://example.com/images/products/10000/1001MINIGOLF/small.jpg

Is there an already assigned variable that contains “https://example.com”, withOUT the mount point? I tried all sorts of incarnations of <@ofbizURL> and <@ofbizContentUrl>, like:

<@ofbizContentUrl fullPath=true >${smallImageUrl}/@ofbizContentUrl
<@ofbizUrl controller=false interWebapp=false webSiteId=none secure=true fullPath=true >${smallImageUrl}/@ofbizUrl

<@ofbizUrl controller=false webSiteId=none secure=true fullPath=true >${smallImageUrl}/@ofbizUrl

The above almost works (controller=false), but still puts the mount point. I Tried webSiteId=none, webSiteId=’’, it STILL puts in the the mount point. How can I make a variable or a macro that just returns “https://example.com”?

Thanks


#2

images should usually be wrapped with @ofbizContentUrl (never @ofbizUrl - they use very different code).

@ofbizContentUrl appends the server prefix configured in url.properties or from the WebSite entity:

# Static Content URLs to make it easy to move the serving load for static content to other machines
# -- thse are for general content such as images, js & css files, or non-dynamic HTML files
content.url.prefix.secure=
content.url.prefix.standard=

If it’s not set there, it appends nothing (same host). It’s meant to be completely separable from the control/navigation host (@ofbizUrl).

There are some server host/path settings in the screen context (e.g., “serverRoot”), and through the “request” object (HttpServletRequest), and a bunch of different java utils to handle URLs, but it’s highly recommended to use/let the macros append it as needed.

If you absolutely need read content path prefix for specific purpose, this method returns the content path prefix on its own: org.ofbiz.webapp.taglib.ContentUrlTag.getContentPrefix(HttpServletRequest)
but it will be empty unless you set it in url.properties or WebSite.


#3

This is how I solved this issue for me:

<#assign hostname = request.getServerName() />
<#assign hostport = request.getServerPort() />
<#assign hostmode = request.getScheme() />
<#assign hostpath = request.getContextPath() />
<#assign hostlang = .lang />
<#assign hostlocale = .locale />

host[${hostname}] port[${hostport}] mode[${hostmode}] path[${hostpath}] lang=[${hostlang}] locale=[${hostlocale}]

Produces: host[example.com] port[443] mode[https] path[/gallery] lang=[en] locale=[en]


#4

Hi Mike,

Just to let you in the loop, some major code improvements were pushed to Git master this weekend. Although it doesn’t cover every single aspect yet, the volume of work is drastic. The Shop web.xml has changed significantly, so there is a fair chance it may conflict with your settings (I assume you have some in the circumstances), so worth a heads up.

Anyhow just to clarify this thread (I applied to some bugfixes which by chance affect this thread a little)…

I might have tiny bit mislead you in comments above (we are very busy here!!), there is one of the macros that practically can wrapper your image link up top:

<@ofbizInterWebappUrl uri="/images/products/10000/1001MINIGOLF/small.jpg" controller=false fullPath=true/>

Although your link is really meant to use @ofbizContentUrl, this one can work too, with the caveat, there was a patch basically by chance applied to today which fixes a bug (related to the /images webapp not having controller) - but I don’t know if it affected you or not.

Separately from that, as I was going to use them as matter of course, I added some method overloads in the class RequestLinkUtil.buildLinkHostPartSafe , it can make some host links (CAVEAT: it does not have the complicated logic of @ofbizUrl and our extensive macros - this is why enthusiasm should be limited for these - same can apply to the “request” variable java servlet API you’re using above, it may be OK in simple cases only).

You would have to check the method comments, but just to finish this story, here is an example use:

<#function buildLinkHostPart secure="" webSiteId="">
  <#if secure?has_content>
    <#return rawString(Static["org.ofbiz.webapp.control.RequestLinkUtil"].buildLinkHostPartSafe(request, webSiteId, secure)!)>
     <#else>
    <#return rawString(Static["org.ofbiz.webapp.control.RequestLinkUtil"].buildLinkHostPartSafe(request, webSiteId, NULLHACK)!)>
    </#if>
</#function>
<li>current: ${escapeVal(buildLinkHostPart(), 'html')}</li>
<li>http: ${escapeVal(buildLinkHostPart(false), 'html')}</li>
<li>https: ${escapeVal(buildLinkHostPart(true), 'html')}</li>