Discussion:
[FreeMarker-user] ensure_starts_with issue
FOX427
2015-06-02 16:28:02 UTC
Permalink
Hi All,

I have <url> node in xml that has link to web site, used 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: <${url}> </a> <${url}>

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.



--
View this message in context: http://freemarker.624813.n4.nabble.com/ensure-starts-with-issue-tp4655468.html
Sent from the freemarker-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
FOX427
2015-06-02 16:40:59 UTC
Permalink
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.

------------------------------------------------------------------------------
Daniel Dekany
2015-06-02 21:16:16 UTC
Permalink
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)?
Post by FOX427
<#if url?starts_with("http")>
${label} <${url}> <br>
<#else>
${label} <http://${url}> <br>
</#if>
--
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
https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Thanks,
Daniel Dekany


------------------------------------------------------------------------------
FOX427
2015-06-04 16:35:47 UTC
Permalink
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>
${entry.label} <${entry.url}> <br>
</#list>

in page source:
item 1 <http://www.ibm.com> <br>
item 2 <www.usatoday.com> <br>



--
View this message in context: http://freemarker.624813.n4.nabble.com/ensure-starts-with-issue-tp4655468p4655482.html
Sent from the freemarker-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Loading...