Forum Discussion

satya's avatar
satya
Expert
8 years ago

Capturing Referrer url in page initialization script

Hi Lithium Team,

 

I am trying to capture the referrer URL of the page. I have used the following code in page initialization script:

<#if http.request.referrer?contains("userregistrationpage")>
--- Following code to display a custom page --
</#if>

The referrer URL contains the word "userregistrationpage", but still it is not going into the if condition. Am I missing something in the code? 

 

Thanks,
Srujana Satya Datla.

  • To troubleshoot, try printing the referrer url. E.g. just put ${http.request.referrer} and see what it spits out.

    One possibility is that it's not actually all lower case.

     

    Try this as well:

    <#if http.request.referrer?lower_case?contains("userregistrationpage")>

    I find that ?lower_case, if perhaps not in this case, works magic in a lot of other cases, because you can always ensure you're comparing two fully lowercase strings.

     

    For example

    <#assign lookfor = "userRegistrationPage"/>
    <#assign ref = http.request.referrer/>
    <#if reflower_case?contains(lookfor?lower_case)>