Error trying to implement gain

I am trying to replicate this example without success. I want to add a list using a template mustache, for example:

<ul>
    <amp-list width=auto
              height=100
              layout=fixed-height
              src="/assets/popular.json">
          <template type="amp-mustache"
                    id="amp-template-id">
              <li>
                  <a href={{url}}>{{title}}</a>
              </li>
          </template>
    </amp-list>
</ul>

My /assets/popular.jsonfile:

{
 "items": [
   {
     "title": "amp-carousel",
     "url": "https://ampbyexample.com/components/amp-carousel"
   },
   {
     "title": "amp-img",
     "url": "https://ampbyexample.com/components/amp-img"
   },
   {
     "title": "amp-ad",
     "url": "https://ampbyexample.com/components/amp-ad"
   },
   {
     "title": "amp-accordion",
     "url": "https://ampbyexample.com/components/amp-accordion"
   }
 ]
}

But I can not get it to work, the values ​​in are jsonnot replaced in the template, I get this error:

Missing URL for attribute 'href' in tag 'a'

I do not know why the value {{url}}will not be correctly replaced by the content json.

I added the necessary to my head scripts.

+4
source share
1 answer

Hugo Jekyll . .

, jekyll, {{tag}} liquid tag. :

<ul>
<amp-list width=auto
    height=100
    layout=fixed-height
    src="/assets/popular.json">
  <template type="amp-mustache"
      id="amp-template-id">
    <li>
      <a href="{% raw %}{{url}}{% endraw %}">{% raw %}{{title}}{% endraw %}</a>
    </li>
  </template>
</amp-list>
</ul>

:

Hugo

<ul>
<amp-list width=auto
    height=100
    layout=fixed-height
    src="/assets/popular.json">
  <template type="amp-mustache"
      id="amp-template-id">
    <li>
      <a class="card related" id={{"{{id}}"}} {{ printf "href=%q" ""{url}}" | safeHTMLAttr }}>
         {{"{{title}}"}}
      </a>
    </li>
  </template>
</amp-list>
</ul>
+7

Source: https://habr.com/ru/post/1649615/


All Articles