Binding a URL from the remote json through parsing error
Description
- I have json data obj as follows:
{ "Obj": [ { "Address1": "test", "Url": "/atm/atms-in-bangalore/epip/floor-tcs-A0002.page" } ] } - I am using amp-list and template-mustache to bind this data to my page.
- But while binding url with href attribute of anchor tag, i am getting parsing error as below
a.ic-more.i-amphtml-error %s amp-bind: Expression compile error in "/atm/atms-in-bangalore/epip/floor-tcs-A0002.page". Parse error on line 1:
/atm/atms-in
^
Expecting 'EOF', '(', '!', '-', '+', 'NAME', '[', 'STRING', 'NUMBER', 'TRUE', 'FALSE', 'NULL', '{', got '/'
- If try binding url: https://www.google.com from json. It is giving me parsing error as for the above url.
How I can fix this issue? I need to bind this url in my current project.
Reproduction Steps
- I have json data obj as follows:
{ "Obj": [ { "Address1": "test", "Url": "/atm/atms-in-bangalore/epip/floor-tcs-A0002.page" } ] } - I am using amp-list and template-mustache to bind this data to my page.
- But while binding url with href attribute of anchor tag, i am getting parsing error as below
a.ic-more.i-amphtml-error %s amp-bind: Expression compile error in "/atm/atms-in-bangalore/epip/floor-tcs-A0002.page". Parse error on line 1:
/atm/atms-in
^
Expecting 'EOF', '(', '!', '-', '+', 'NAME', '[', 'STRING', 'NUMBER', 'TRUE', 'FALSE', 'NULL', '{', got '/'
Relevant Logs
`a.ic-more.i-amphtml-error %s amp-bind: Expression compile error in "/atm/atms-in-bangalore/epip/floor-tcs-A0002.page". Parse error on line 1:
/atm/atms-in
^
Expecting 'EOF', '(', '!', '-', '+', 'NAME', '[', 'STRING', 'NUMBER', 'TRUE', 'FALSE', 'NULL', '{', got '/'`
Browser(s) Affected
Chrome, Firefox, Safari, Edge
OS(s) Affected
No response
Device(s) Affected
No response
AMP Version Affected
No response
The following code snippet works for me in the playground:
<amp-state id="localState">
<script type="application/json">
{
"Obj": [{"Address1": "test", "Url": "/atm/atms-in-bangalore/epip/floor-tcs-A0002.page"}]
}
</script>
</amp-state>
<amp-list layout="fixed-height" items="Obj" height="3000" src="amp-state:localState">
<template type="amp-mustache">
<a href={{Url}}>{{Address1}}</a>
</template>
</amp-list>
Can you tell me more about the issue? Maybe I am misunderstanding?
I have not used amp-state because I need to perform some operation on my json data.
So I have used exportFunction('dummyFunc', function(){}); to fetch the data. After that when I try to bind the url
<a href="{{url}}" class="ic-more">know more</a> I ma getting parse error as described above.
Can you please send me the full code you are having issues with in a playground.amp.dev link?
Sorry That is confidential code and data. Can not share on playground. But they way you tried, I also tried at my local it is working fine with the following binding
<div class="button-group">
<a href="{{dirUrl}}" class="ic-btn"
>Get Directions</a
>
<a href="{{url}}" class="ic-more"
>know more</a
>
</div> .
But When I move this component to AEM. then this is coming as
<div class="button-group">
Get Directions
Know More
</div> without the anchor tag and link url.
But When I am using [href] binding <div class="button-group">
<a [href]="{{dirUrl}}" class="ic-btn"
>Get Directions</a
>
<a [href]="{{url}}" class="ic-more"
>know more</a
>
</div>
Then i am getting parsing error.
My issue is fixed using following code. href was not binding with dirUrl on page load. But when I tried with div and navigateTo event it is working fine.
<div class="ic-btn" on="tap:AMP.navigateTo(url='{{dirUrl}}', target='_blank')" > Get Direction </div>
But I am still not sure why it is not working with href.
But anyway thanks for quick reply and looking into my issue.