Forum Discussion
kiettuongwork there are several things you can try, I would do it as follows:
<#-- assuming URL: https://communitystg.digi.com.my/t5/Blog/bg-p/11112222 with the goal to extract the number at the end, e.g. 11112222 --> <#assign url = http.request.url /> <#-- first split away any URL parameters, that's the stuff after a question mark "?" what you seem to want is a url-path element, basically what we want is everything before a possible question mark --> <#assign urlparts = url?split("?")?first /> <#-- we then split that first part at every slash "/" --> <#assign urlparts = url?split("?")?first?split("/") /> <#-- and eventually select just the last bit of that sequence to get what you want --> <#assign urlparts = url?split("?")?first?split("/")?last /> <#-- of course you do not need to do that assignment 3 times, once is enough, e.g. like this: --> <#assign urlparts = url?split("?")?first?split("/")?last /> ${urlparts}
hope it helps!
PS: The link to your stage instance of Lithium is blocked by .htaccess, therefore nobody can see your demo-links
I have tried them but could not work. You may need review my previous comments to see
- luk8 years agoBoss
What did not work, you need to provide more information if you want help...this is not your official Lithium support...we cannot see what you are doing, therefore you need to be a bit more detailed in the description of your issues...
if I go to try.freemarker.org
and enter this in the template field:
<#assign url = "https://communitystg.digi.com.my/t5/Blog/bg-p/11112222" /> <#-- first split away any URL parameters, that's the stuff after a question mark "?" what you seem to want is a url-path element, basically what we want is everything before a possible question mark --> <#assign urlparts = url?split("?")?first /> <#-- we then split that first part at every slash "/" --> <#assign urlparts = url?split("?")?first?split("/") /> <#-- and eventually select just the last bit of that sequence to get what you want --> <#assign urlparts = url?split("?")?first?split("/")?last /> <#-- of course you do not need to do that assignment 3 times, once is enough, e.g. like this: --> <#assign urlparts = url?split("?")?first?split("/")?last /> ${urlparts}
it works perfectly, outputting "11112222"...so if that's not what you want, then you have to be more specific.
- kiettuongwork8 years agoContributor
Hi,
Sorry make you confuse. I though you followed screenshot and code I sent before.
I am using code you shared under component. And I do not fix URL "https://communitystg.digi.com.my/t5/Blog/bg-p/11112222"
I retrieve request URL under component.
And it always display url = https://communitystg.digi.com.my/t5/util/componentrenderpage/component-id/recent-blog-posts?render_behavior=raw&page=1
instead of https://communitystg.digi.com.my/t5/Blog/bg-p/11112222 as display on address bar.
Please check screenshot as below.
My expect: can get url of address bar in component
<#assign url = http.request.url />
url should be https://communitystg.digi.com.my/t5/Blog/bg-p/11112222 so then I can use split function as you provided to get "11112222" for query data later.
Thanks for your support.
- luk8 years agoBoss
I'm not sure, but it seems that what
coreNode.id
returns is not the blog, but the id of your instance/community, to what quilt/page (like BlogPage etc.) do you add this custom component?
Is it doing the same if you copy the entire code into a differently named component (like "cmp.blog.recent")? (might be that there is a standard component with the same name, just a guess...that could cause trouble).
you could kind of make your code more robust by checking that you are on a blog node, like:
<#if coreNode.nodeType == "blog"> // do your stuff
<#else>
// not in a blog node </#if>