Do you build things with AMP? Fill out the new AMP Developer Survey!
  • websites



Cet exemple utilise la fonctionnalité expérimentale suivante : amp-date-pickeramp-lightbox-gallery. Activez l'expérience via le bouton ci-dessous. Certains composants nécessitent aussi l'activation d'AMP Dev Channel. Learn more about experimental features.


This is a sample showing how to implement a hotel page. It features room availability based on date selection and a pet-friendly filter on page data. The room list resizes automatically after filtering and the user is shown a message in case of no results. The user can enlarge photos and swipe rooms by using a gallery.


We use a few AMP extensions to dynamically render a list of rooms. We use amp-form to send a filter request to the server.

<script async custom-element="amp-form" src=""></script>

We use amp-mustache as a template rendering engine for amp-list.

<script async custom-template="amp-mustache" src=""></script>

We use amp-list to dynamically show a list of rooms.

<script async custom-element="amp-list" src=""></script>

We use amp-bind to filter rooms based on their availability.

<script async custom-element="amp-bind" src=""></script>

We use amp-date-picker to simplify entering dates for checking room availability.

<script async custom-element="amp-date-picker" src=""></script>

We use amp-lightbox-gallery to make it possible enlarge an image upon clicking ans swipe throughout all the images.

<script async custom-element="amp-lightbox-gallery" src=""></script>

We use amp-fit-text to fit the hotel name to the available space.

<script async custom-element="amp-fit-text" src=""></script>

Searching for available rooms

This sample shows how to search for available rooms based on date selection. You can implement an availability search by using the amp-date-picker as input of a form.

Here we are using type=range as we need 2 dates: the arriving and leaving date of an hotel reservation. Upon receiving a submit-succes event from the form response, we set the value of a global variable rooms to the form response. We are using the variable rooms throughout the sample to access the response from other AMP components.

<form method="GET"
            rooms: event.response
  <amp-date-picker id="picker"
    <input name="start"
    <input name="end"
    <button on="tap: picker.clear">Clear</button>
  <input type="submit"
    value="Check Availability">

Client-side filtering

We want to make it possible for the user to filter rooms by pet friendliness. The filter shouldn't require an additional network request, instead it should work client-side. We implement a filter by adding a checkbox which sets a new variable, filterPetFriendly, whenever the value changes.

<label>Show only pet friendly rooms:
  <input type="checkbox"
      showPetFriendlyOnly: event.checked

Filter implementation

We use amp-bind-macro to implement a function which filters the amp-list content based on the pet-friendly variable. By using amp-bind-macro we avoid duplicating the filter expression across the page.

<amp-bind-macro id="filteredRooms"
  expression="rooms.filter(room => showPetFriendlyOnly ? room.petFriendly : true)">

Room list initial state

We are using amp-state to set the initial value of the variable rooms to the list of rooms returned by the server.

This is necessary for client-side filtering to work after the initial page load. We are using the variable rooms throughout the sample to access this list from other AMP components.

Both, amp-list and amp-state, use the same endpoint.

<amp-state id="rooms"

Room list

We are using amp-list to show a list of rooms. We bind the value of the src variable to the result of the function filterRooms so that we can show the available rooms based on the user selection.

The user can view an enlarged version of each image by clicking on it. This can be implemented using the amp-lightbox-gallery by adding the lightbox attribute to every amp-img; the alt parameter content adds also a caption for every image in the lightbox gallery.

amp-list content takes the entire height on the page from the height attribute; after filtering, it could take unused space: we are resizing by binding the height attribute to the result of the height of the image plus the margins multiplied by the length of the list.

<amp-list class="rooms"
  [height]="(80 + (16*2)) * filteredRooms().length"
  <template type="amp-mustache">
    <amp-img width="108"
    <div>{{name}} {{#petFriendly}}🐾{{/petFriendly}}</div>

Handling empty list content

In case no rooms are available, we are showing a message to inform the user. We hide the

message by default and show it when the list is not empty. We are calling filteredRooms() function

from the amp-bind-macro to get the list of rooms filtered by user selection.

<p hidden
  [hidden]="filteredRooms().length > 0">Sorry, no rooms available</p>
Besoin de plus amples explications ?

Si les explications de cette page ne répondent pas à vos questions, n'hésitez pas à contacter d'autres utilisateurs d'AMP pour discuter de votre cas d'utilisation spécifique.

Se rendre sur Stack Overflow
Une fonctionnalité n'a pas encore été expliquée ?

Le projet AMP encourage fortement votre participation et vos contributions ! Nous espérons que vous deviendrez un membre régulier de notre communauté open source, mais nous serons également ravis de recevoir des contributions ponctuelles concernant les questions qui vous intéressent particulièrement.

Modifier l'exemple sur GitHub