Forum Discussion

Inactive User's avatar
Inactive User
12 years ago

Getting tag from URL

We are trying to edit the TagViewPage and need to know which tag is currently being displayed with Freemarker. I tried every attribute or parameter call I could find but to no success.

 

Currently, my work around is:

<#assign url = http.request.url />
<#assign urlSections = url?split("/") />
<#if urlSections?size gte 5>
<#assign tag = urlSections[5] />
<#else>
<#assign tag = "" />
</#if>

 

(I'm using 5 since the URL will end up being this [for now]: https:(0)/(1)/(2)domain.com/(3)t5/(4)tag/(5)TAG_NAME/tg-p/board-id/BOARD_ID)

 

Anyove have a better idea or know of a call that will work? Thanks.

  • I think you're workaround is good, one thing you might consider changing is instead of relying on the length of the URL sections and the location of the tag-value section within the array, you could instead rely on the order. In the case of the TagViewPage the URL section representing the tag value will always be preceded by a URL section called "tag". The creates a key/value pair like this: /tag/<tag-value>. So the code might look something like this:

     

    <#assign urlSections = http.request.url?split("/") />
    <#assign tag = "" /> 
    
    <#list urlSections as urlSection>
        <#if urlSection_index gt 0 && urlSections[urlSection_index - 1] == "tag">        
            <#assign tag = urlSection />
        </#if>
    </#list>

3 Replies

  • AdamA's avatar
    AdamA
    Khoros Oracle
    12 years ago

    I think you're workaround is good, one thing you might consider changing is instead of relying on the length of the URL sections and the location of the tag-value section within the array, you could instead rely on the order. In the case of the TagViewPage the URL section representing the tag value will always be preceded by a URL section called "tag". The creates a key/value pair like this: /tag/<tag-value>. So the code might look something like this:

     

    <#assign urlSections = http.request.url?split("/") />
    <#assign tag = "" /> 
    
    <#list urlSections as urlSection>
        <#if urlSection_index gt 0 && urlSections[urlSection_index - 1] == "tag">        
            <#assign tag = urlSection />
        </#if>
    </#list>
  • Inactive User's avatar
    Inactive User
    12 years ago
    Like this approach much better. Thanks.
  • Our approach was the create a function to grab the tag (if available)

     

    <#function getTag>
      <#assign tag = webuisupport.path.parameters.name.get("tag-id")! />
    
      <#if tag??>
        <#return tag.tagText! />
      <#else>
        <#return false />
      </#if>
    </#function>