Get Sub-string From URL in FTL

10 views
Skip to first unread message

Vivek

unread,
Feb 20, 2018, 8:31:36 AM2/20/18
to Hippo Community
Hi,

I have the below URL string say /level1/level2/level3/_________________

Now I need to get the sub-string till level 3. i.e. /level1/level2/level3 . How can I achieve it?

Thanks,

Jasper Floor

unread,
Feb 20, 2018, 9:09:48 AM2/20/18
to Hippo Community
Get the URL (from the request) and do a regex match. 

mvg,
Jasper

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-community@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.

Woonsan Ko

unread,
Feb 20, 2018, 10:56:54 AM2/20/18
to hippo-c...@googlegroups.com
<#assign s="/level1/level2/level3/a/b/c.html">
<#assign res=s?matches(r"^(\/[^\/]+){3}(.*)$")>
<#assign remaining="">
<#if res>
  <#assign remaining=res?groups[1]>
</#if>
${remaining} <#-- "/a/b/c.html" -->

Regards,

Woonsan

References:
 

Thanks,

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-community@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.

Woonsan Ko

unread,
Feb 20, 2018, 10:57:57 AM2/20/18
to hippo-c...@googlegroups.com
On Tue, Feb 20, 2018 at 10:56 AM, Woonsan Ko <woons...@bloomreach.com> wrote:


On Tue, Feb 20, 2018 at 8:31 AM, Vivek <vivek....@gmail.com> wrote:
Hi,

I have the below URL string say /level1/level2/level3/_________________

Now I need to get the sub-string till level 3. i.e. /level1/level2/level3 . How can I achieve it?

<#assign s="/level1/level2/level3/a/b/c.html">
<#assign res=s?matches(r"^(\/[^\/]+){3}(.*)$")>
<#assign remaining="">
<#if res>
  <#assign remaining=res?groups[1]>
Sorry, it should be 'res?groups[2]'.

Woonsan

Vivek

unread,
Feb 22, 2018, 12:16:27 AM2/22/18
to Hippo Community
Hi, I do need last url, I need parent URL till 3 level. say /level1/leve2/level3


On Tuesday, February 20, 2018 at 9:27:57 PM UTC+5:30, woonsan.ko wrote:
On Tue, Feb 20, 2018 at 10:56 AM, Woonsan Ko <woons...@bloomreach.com> wrote:


On Tue, Feb 20, 2018 at 8:31 AM, Vivek <vivek....@gmail.com> wrote:
Hi,

I have the below URL string say /level1/level2/level3/_________________

Now I need to get the sub-string till level 3. i.e. /level1/level2/level3 . How can I achieve it?

<#assign s="/level1/level2/level3/a/b/c.html">
<#assign res=s?matches(r"^(\/[^\/]+){3}(.*)$")>
<#assign remaining="">
<#if res>
  <#assign remaining=res?groups[1]>
Sorry, it should be 'res?groups[2]'.

Woonsan
 
 

Thanks,

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com

RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.

Woonsan Ko

unread,
Feb 22, 2018, 9:11:55 AM2/22/18
to hippo-c...@googlegroups.com
<#assign s="/level1/level2/level3/a/b/c.html">
<#assign res=s?matches(r"^((\/[^\/]+){3})(.*)$")>
<#assign firstThree="">
<#if res>
  <#assign firstThree=res?groups[1]>
</#if>
${firstThree} <#-- "/level1/level2/level3" -->


To post to this group, send email to hippo-community@googlegroups.com

RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.

Woonsan Ko

unread,
Feb 22, 2018, 10:01:45 AM2/22/18
to hippo-c...@googlegroups.com
Also, for those who want to test FreeMarker templates on the fly, try this at any time with the examples:

Cheers,

Woonsan

Reply all
Reply to author
Forward
0 new messages