4

この例を再現しようとしていますが、成功していません。mustache次のように、テンプレートを使用してリストを追加します。

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

私の/assets/popular.jsonファイルは次のとおりです。

{
 "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"
   }
 ]
}

しかし、私はそれを機能させることができませんjson.テンプレート内の値が置き換えられていません.次のエラーが発生します:

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

{{url}}値が の内容に適切に置き換えられない理由がわかりませんjson

頭に必要なものを追加しましたscripts

4

1 に答える 1

7

最近、私はJekyllからHugoに移行しており、同じ問題に直面しています。以下は両方の解決策です。

ジキル

問題は私が使用し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>

更新より詳細な説明を書きました

ヒューゴ

<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>
于 2016-07-30T12:36:43.467 に答える