My site's path is as follows : https://{server-name}/t5/Blog/bg-p/11112222
<#assign url= http.request.referrer/> <#assign url = url?keep_before("?")?keep_after("bg-p/")?lower_case/> <#assign url1= '/blogs/id' + url + '/threads/recent/count'/> <#assign url2 = "/blogs/id/11112222/threads/recent/count" /> <#assign sub_blog = "11112222" /> <#assign count = rest("${url2}").value?number>
Please show me the difference of url1 và url2 ( although I see both variables get the same value )
The above code has no errors but when I replace
<#assign count = rest("${url2}").value?number>
become
<#assign count = rest("${url1}").value?number>
I get the following error message:
REST Error:
status="error"
code="501"
message="Unknown path element at node 'board'."
----
FTL stack trace ("~" means nesting-related):
- Failed at: #assign count = rest("${url1}").value... [in template "preview" at line 12, column 1]
----
@trinhdinhphuong- Can you please print the url1 value? There must be difference else there wouldn't be an issue.
I printed it but both url1 and url2 the same value:
/blogs/id/11112222/threads/recent/count
@trinhdinhphuong - You forget to add a slash (/) after id on url1. I have updated your code. Please try now.
<#assign url= http.request.referrer/> <#assign url = url?keep_before("?")?keep_after("bg-p/")?lower_case/> <#assign url1= '/blogs/id/' + url + '/threads/recent/count'/> <#assign url2 = "/blogs/id/11112222/threads/recent/count" /> <#assign sub_blog = "11112222" /> <#assign count = rest("${url2}").value?number>
I realized that problem before sending a second message.
I edited it like you said but i still get the same error.
REST Error: path="https://{server-name}/tvrmi89547/restapi/vc/blogs/id//threads/recent/count?restapi.response_style=view" status="error" code="501" message="Unknown path element at node 'board'." ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign count = rest("${url1}").value... [in template "preview" at line 12, column 1] ---- Java stack trace (for programmers): ---- lithium.coreapi.rest.RestApiTemplateModelException: [... Exception message was already printed; see it above ...] at lithium.rest.StandardRestApiRequestSupport.unwrapLocalRestResponse(StandardRestApiRequestSupport.java:145) at lithium.template.FreeMarkerRestMethods$RestMethod.execute(FreeMarkerRestMethods.java:525) at lithium.template.FreeMarkerRestMethods$RestMethod.exec(FreeMarkerRestMethods.java:506) at lithium.template.FreeMarkerRestMethods$CachedRestMethod.exec(FreeMarkerRestMethods.java:447) at freemarker.core.MethodCall._eval(MethodCall.java:65) at freemarker.core.Expression.eval(Expression.java:81) at freemarker.core.Dot._eval(Dot.java:41) at freemarker.core.Expression.eval(Expression.java:81) at freemarker.core.Expression.evalAndCoerceToStringOrUnsupportedMarkup(Expression.java:107) at freemarker.core.BuiltInForString.getTargetString(BuiltInForString.java:34) at freemarker.core.BuiltInForString._eval(BuiltInForString.java:29) at freemarker.core.Expression.eval(Expression.java:81) at freemarker.core.Assignment.accept(Assignment.java:134) at freemarker.core.Environment.visit(Environment.java:326) at freemarker.core.Environment.visit(Environment.java:332) at freemarker.core.Environment.process(Environment.java:305) at freemarker.template.Template.process(Template.java:378) at
@trinhdinhphuong - As you can see in your error you are not getting blogs id blogs/id//threads. This is the reason you are getting an error.
path="https://{server-name}/tvrmi89547/restapi/vc/blogs/id//threads/recent/count?restapi.response_style=view" status="error"
Just to give you more info about the issue, http.request.referrer causing the issue. This context object will only work if you will reach the destination URL by clicking on any link. If you will open the page without clicking on any link it will give you current page URL, not the page where you came from. You can share more info what do you want to achieve, maybe I can share any other workaround.
When I paste the following path into the browser, I want to get the url and then get the string after "bg-p /" and before "?".
https://{domain-name}/t5/Blog/bg-p/11112222?abcd
Thanks @TariqHussain
@trinhdinhphuong - You don't need to use long methods just to get that, there is a context object which will give you the exact result.
${coreNode.id}
<#assign url1= '/blogs/id/' + coreNode.id + '/threads/recent/count'/>
If above method doesn't work you can try this one.
<#assign url= http.request.url /> <#assign url = url?keep_before("?")?keep_after("bg-p/")?lower_case/> <#assign url1= '/blogs/id/' + url + '/threads/recent/count'/> <#assign url2 = "/blogs/id/11112222/threads/recent/count" /> <#assign sub_blog = "11112222" /> <#assign count = rest("${url2}").value?number>
I tried your two solutions but it didn't work.
I have printed out the following values:
${coreNode.id} : tvrmi89547 (But I need the "11112222" string)
http.request.referrer: https://{server-name}/t5/Blog/bg-p/11112222
http.request.url: https://{server-name}/t5/util/componentrenderpage/component-id/recent-blog-posts?render_behavior=raw...
I want to get the string: https://{server-name}/t5/Blog/bg-p/11112222 , So I can’t use “http.request.url” and “coreNode.id”.
I need the string “11112222” in http.request.referrer
@trinhdinhphuong- On which page you want to implement this? e.g (Blog Article Page, Blog Page etc). The error you are getting because http.request.referrer is not returned what your code expected.
I have added a condition(<#if url?contains("bg-p") >) which will restrict the error. Your code for the component should be inside that if condition.
<#assign url= http.request.referrer/> <#if url?contains("bg-p") > <#assign url = url?keep_before("?")?keep_after("bg-p/")?lower_case/> <#assign url1= '/blogs/id/' + url + '/threads/recent/count'/> <#assign url2 = "/blogs/id/11112222/threads/recent/count" />
<#assign sub_blog = "11112222" /> <#assign count = rest("${url2}").value?number>
</#if>
Welcome to the Technology board!
Curious about our platform? Looking to connect on social technology? You've come to the right place!