Forum Discussion

phani's avatar
phani
Advisor
10 years ago

Get hash value from url in freemarker

Hi, How do I get the value after hash (#) from a URL using FreeMarker.

E.X.: Page URL = http://community.lithium.com/t5/Support-Forum/bd-p/lisupport#token=12345).

How can i get the value of "token"?

 

Is there any FreeMarker context object available like http.request.parameters.name.get? if not could anyone suggest workaround for this in FreeMarker ?

 

Your help could be highly appreciated.

Thanks & Regards,

Phani

4 Replies

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    10 years ago

    Hi phani

     

    I believe that the URL fragment is not sent to the server so I am afraid that would not be possible. You can access it via javascript inside a custom component if that helps.

     

    Thanks,

  • phani's avatar
    phani
    Advisor
    10 years ago

    Hi PaoloT,

     

    Thanks for your quick response.

     

    We are able to get the value by using http.client.response FreeMarker context object, if the parameter passed with '&' 

    E.X.: /plugins/custom/community_name/community_name/your_endpoint?data=test&token=1234

    Code Snippet: <#assign token = http.request.parameters.name.get("token","")/>

     

    In our requirement we are calling the endpoint with hash value. For us Javascript is not preferable option.

    E.X.: /plugins/custom/community_name/community_name/your_endpoint#token=1234

     

    Could you please provide more description on your statement "URL fragment is not sent to the server", it might helpful for us to try some workaround?

     

    Regards,

    Phani

     

  • phani - As the freemarker executes on the server and not on the client side, so you cannot get the # fragments because they never reach server. They stay on the client side, so you could only read it using a client side language. JS or jQuery.

    I hope this helps.
  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    10 years ago

    Hi phani

     

    these parameters that you are able to read are HTTP request parameters and that's the reason why you can read them (because they are part of the request sent to the server so it can read it). On the contrary, a fragment is not an HTTP request parameter so it's not sent in the request.

     

    Hope this helps,