0
votes

I have an amp page that is called on:

https://expample.amp.com?id=1234abc

(Not the real url.)

<amp-list src="https://some.external-url.com/?dataid=NEEDS_ID"
  layout="responsive"
  items="Result"
  width="100"
  height="100" 
>
  <template type="amp-mustache">
  <p>{{FullName}}</p>
  </template>
</amp-list>

I want my id query param to be injected into the src of the amp-list tag at NEEDS_ID.

I already checked the QUERY_PARAM docs but couldn't understand what exactly I'm supposed to do.

I've already tried src="https://some.external-url.com/?dataid=QUERY_PARAM(id)" but that didn't work.

Any pointers/references?

My silly-and-dumb solution to this was writing an EJS node server, that parses a <%= query.id %> in that url and then sends that page to the client. Is that the correct way to do it?

2

2 Answers

0
votes

I do strongly suppose that the call to the Url independent to the AMP Page, results in valid json data. If this is the case, you may face following problems:

  1. CORS
  2. your result data is somehow corrputed

As for me, this saved me a lot of time:

public function getData(){

   echo header('Access-Control-Allow-Origin: https://amp-YOUR-SITE');
   echo header('Access-Control-Allow-Credentials: true');
   echo json_data;
}
0
votes
https://expample.amp.com?slug=1234abc
<amp-list id="time"
            layout="fixed-height"
            height="18"
            src="https://api.exemple.com/posts?slug=QUERY_PARAM(slug)"
            binding="refresh"
            data-amp-replace="QUERY_PARAM"
            single-item
            items=".">
    <template type="amp-mustache">
    <p>{{title}}</p>
    <p>{{content}}</p>
    </template>
  </amp-list>