AMP
  • websites

Paged List

Introduction

Often, users requests data that could fill multiple pages of content, so web applications must provide a way for users to navigate across pages of data. This pattern appears in search results, product browse pages, and more. Here we implement paged navigation using the amp-bind and amp-list components.

Setup

First we include amp-bind to track and mutate the page state.

<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>

Next we include amp-list to request and display the lists of products.

<script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>

Finally, we include amp-mustache to render the mustache templates inside the <amp-list>.

<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>

Styles

No additional styles are necessary, but you can optionally add styles to change the layout or the look and feel of the page.

Implementation

We use an <amp-list> element to render the product cards. An <amp-state> element initializes and tracks the number of pages in the response. An overflow element ensures that the user is able to reveal more content if any of the products are truncated by the bottom of the <amp-list>.

<amp-list class="paged-amp-list" layout="fixed-height" height="720" src="https://amp.dev/documentation/examples/interactivity-dynamic-content/paged_list/search" [src]="'https://amp.dev/documentation/examples/interactivity-dynamic-content/paged_list/search?page=' + pageNumber" binding="no" reset-on-refresh single-item>
          <template type="amp-mustache">
            <p class="info">Page {{currentPage}} of {{pageCount}}</p>
            <div class="items">
              {{#products}}
              <div class="item">
                <amp-img layout="responsive" class="image" width="320" height="240" src="{{image}}"></amp-img>
                <strong class="title">{{title}}</strong>
                <p class="copy">{{copy}}</p>
              </div>
              {{/products}}
            </div>
          </template>
          <div overflow>
            <button>Show more</button>
          </div>
</amp-list>
<div class="navigation">
  <button class="prev" hidden [hidden]="pageNumber < 2" on="tap: AMP.setState({ pageNumber: pageNumber - 1 })">
    Previous
  </button>
  <button class="next" [hidden]="page ? pageNumber >= page.items.pageCount : false" on="tap: AMP.setState({ pageNumber: pageNumber ? pageNumber + 1 : 2 })">
    Next
  </button>
</div>
<amp-state id="page" src="https://amp.dev/documentation/examples/interactivity-dynamic-content/paged_list/search" [src]="'https://amp.dev/documentation/examples/interactivity-dynamic-content/paged_list/search?page=' + pageNumber">
</amp-state>
자세한 설명이 필요하신가요?

이 페이지의 설명만으로 궁금한 점이 모두 해결되지 않는다면 다른 AMP 사용자에게 문의하여 구체적인 활용 사례를 논의해 보세요.

Stack Overflow로 이동
설명이 부족한 기능을 발견하셨나요?

AMP 프로젝트는 여러분의 참여와 기여를 적극 환영합니다! 오픈 소스 커뮤니티를 통해 지속적으로 활동해 주셔도 좋지만 관심 있는 주제에 한 번만 기여하셔도 큰 도움이 됩니다.

GitHub에서 샘플 수정하기