Public
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Occasional Advisor

Error passing variable in function : Unknown path element at node 'board'

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]

----

11 Replies 11
Highlighted
Honored Contributor

@trinhdinhphuong- Can you please print the url1 value? There must be difference else there wouldn't be an issue. 

Give kudos if you find my posts helpful or mark solution if it answers your query.
Tariq
Highlighted

I printed it but both url1 and url2 the same value:

/blogs/id/11112222/threads/recent/count

 

Highlighted

Do you have any other solution, @TariqGrazitti ?

Highlighted

@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>

  

Give kudos if you find my posts helpful or mark solution if it answers your query.
Tariq
Highlighted

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 

 

Highlighted

@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. 

 

 

Give kudos if you find my posts helpful or mark solution if it answers your query.
Tariq
Highlighted

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 @TariqGrazitti

Highlighted

@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>

 

Give kudos if you find my posts helpful or mark solution if it answers your query.
Tariq
Highlighted

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