Forum Discussion

kiettuongwork's avatar
kiettuongwork
Contributor
7 years ago

How to retrive info from query string and pass into component in Lithium

Hi Support Team,

 

I have tried to check how component in Lithium queries data for 4 pages above.

There is an issue need to get advise from Lithium support.

Scenario:

Once we access URL as below 

We want to get last part of URL in this case is "Reviews" and then pass that parameter to component name "recent-blog-posts"

And in component we will get parameter by using code as below

<#assign category = http.request.parameters.name.get("category", "") />

Question: 

  1. Where should check that component is used in admin of Lithium?
  2. How can we parse parameter from URL after /bg-p and then pass that parameter to component recent-blog-posts?
    1. 11112222
    2. Reviews
    3. LetsInspire
    4. NewAtDigi

Thanks,

Mickey

4 Replies

  • kiettuongwork

    You can use the freemarker split function to get the last part of the URL

    <#assign url = http.request.url />
    <#assign parts = url?split("/") />

     

  • VikasB's avatar
    VikasB
    Boss
    7 years ago

    kiettuongwork

    1. If you want to get the last part of the URL then you have to split it with "/" and need to fetch only last part like below

    <#assign url = http.request.url />
    <#assign parts = url?split("/") />
    <#assign required_part = parts[(parts?size)-1] />
    ${required_part}

    It will print the last part of the page URL

    11112222
    Reviews
    LetsInspire
    NewAtDigi

    2. If there is the single parameter like mentioned in your new URL(https://community.lithium.com?category=123) then you can split it with "=" and get the last part.  See here https://prnt.sc/j12wot

    3. If you are on blog page or category page and just want to get the last part of the URL then you can use ${coreNode.id} 

     

    LMK the exact URL from which you want to get the last part of the URL. 

     

     

  • kiettuongwork's avatar
    kiettuongwork
    Contributor
    7 years ago

    Hi,

     

    I tried as below code in component recent-blog-posts

    <#assign url = http.request.url />
    <#assign parts = url?split("/") />
    <#assign category = parts[(parts?size)-1] />
    Hello category ${category}

     

    You can see result at 

    https://communitystg.digi.com.my/t5/Blog/bg-p/11112222

     

    Hello category = recent-blog-posts?render_behavior=raw&page=1

     

    It should be Hello category = 11112222

     

    Could you please advise how to retrieve 11112222?

     

    Thanks