Skip to content

Instantly share code, notes, and snippets.

@AlanJenkinsVS
Created November 29, 2018 11:07
Show Gist options
  • Save AlanJenkinsVS/b51d6e3f47d8ab75121ad271588f0935 to your computer and use it in GitHub Desktop.
Save AlanJenkinsVS/b51d6e3f47d8ab75121ad271588f0935 to your computer and use it in GitHub Desktop.
Using AMP to display a dropdown showing options for Results per Page
<!--
Expect back-end src to respond with a results_per_page array of objects
{
"items": {
"results_per_page" :[{
"value": "10",
"text": "10",
"selected": true
},{
"value": "50",
"text": "50",
"selected": false
},{
"value": "100",
"text": "100",
"selected": false
},{
"value": "all",
"text": "All",
"selected": false
}]
}
}
-->
<amp-list
layout="flex-item"
height="40"
src="/filters.json.php"
[src]="'/filters.json.php?<?=$initial?>">
<template type="amp-mustache">
{{current_items}}
<select on="change:AMP.pushState({ filtering: { results_per_page: event.value }, product_list: { items: { loading: true } } })">
<optgroup label="Results per Page">
{{#results_per_page}}
{{#selected}}
<option value="{{value}}" selected>View {{text}}</option>
{{/selected}}
{{^selected}}
<option value="{{value}}">View {{text}}</option>
{{/selected}}
{{/results_per_page}}
</optgroup>
</select>
</template>
</amp-list>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment