ensure_starts_with issue

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ensure_starts_with issue

FOX427
Hi All,

I have <url> node in xml that has link to web site, used <a href="${url}"> and it was fine as long as node has link starting with "http://"(for example, "http://www.yahoo.com"), but some nodes don't have it and because of that i am getting this link attached to the path in my url in the browser, for example, localhost:7001/product/www.google.com instead of just going to www.google.com.

Searched freemarker docs and found ensure_starts_with that should have helped with this problem:

<a href="${url}"?ensure_starts_with("http://")>

Still getting url attached to my controller path.
I am using Spring framework.

I think I can do string manipulations and fix this problem but was wondering if there is better solution. Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ensure_starts_with issue

FOX427
for now I have added this and it works so far:

<#if url?starts_with("http")>
     <a href="${url}">${label}<br>
<#else>
     <a href="http://${url}">${label}<br>
</#if>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ensure_starts_with issue

Daniel Dekany
ensure_starts_with should work for this too, and it's terser than what
you do. Could you show the concrete template snippet, and the
resulting output (copy-parsed from the browser source view)?


Tuesday, June 2, 2015, 6:40:59 PM, FOX427 wrote:

> for now I have added this and it works so far:
>
> <#if url?starts_with("http")>
>       ${label} <${url}>  <br>
> <#else>
>       ${label} <http://${url}>  <br>
> </#if>
>
>
>
> --
> View this message in context:
> http://freemarker.624813.n4.nabble.com/ensure-starts-with-issue-tp4655468p4655469.html
> Sent from the freemarker-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> FreeMarker-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

--
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ensure_starts_with issue

FOX427
Sorry for late response.

in XML:

<items>
    <entry>
        <label>item 1</label>
        <url>http://www.ibm.com</url>
    </entry>
    <entry>
        <label>item 2</label>
        <url>www.usatoday.com</url>
    </entry>
</items>

in ftl:

<#list items.entry as entry>
    <a href="${entry.url}"?ensure_starts_with("http://")>${entry.label}<br>
</#list>

in page source:
item 1<br>
item 2<br>
Loading...