Home > Web Front-end > CSS Tutorial > How to automatically provide rich content suggestions when searching in Google AMP?

How to automatically provide rich content suggestions when searching in Google AMP?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-09-06 21:49:02
forward
1177 people have browsed it

如何在Google AMP中搜索时自动提供丰富的内容建议?

To implement auto-suggestions of rich content to the user while typing in the input field, we will use the "amp-autocomplete" script from the Google AMP framework. Autocomplete input fields means suggesting relevant content to the user as they start typing.

Let us discuss this method through an example as shown below −

method

We will use the "amp-autocomplete" script to add auto-suggestions for rich content on our pages. We will also use the Google AMP framework's "amp-form" script in order to use its amp-form component and display it in the UI, and "amp-mustache" to provide us with templates to use in our web pages.

The Chinese translation of

Scripts Used Here

is:

Scripts Used Here

  • Load amp-autocomplete script −

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

This script is used to load the amp-autocomplete function, which can help us add automatic suggestions for rich content on web pages.

  • Load amp-form script −

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

This script is used to load the amp-form component of the Google AMP framework, which we can use in our application

  • Load amp-project script −

<script async src="https://cdn.ampproject.org/v0.js"></script>
Copy after login

This script is used to load amp-project, allowing us to use different features of the Google AMP framework.

  • Load amp-mustache script −

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

This script is used to load the amp-mustache template, which allows us to use templates in HTML files.

We will use the JSON object below as an example of complex data and use this data to pass it to amp-autocomplete to provide suggested results.

JSON object usage -

{
   "items": [
      {
         "name": "Luffy",
         "country": "India"
      },{
         "name": "Nami",
         "country": "USA"
      },{
         "name": "Zoro",
         "country": "Canada"
      }
   ]
}
Copy after login

We will then use the amp-form component and pass it a JSON object to provide us with auto-suggested results. We will use the AMP mustache template format of the form -

<template type="amp-mustache" id="amp-template-custom">
   <div data-value="{{name}}, {{country}}">
      {{name}}, {{country}}
   </div>
</template>
Copy after login

Example

Our index.html file will look like this −

File name: index.html




   
   
   <script async src="https://cdn.ampproject.org/v0.js"></script>
   
   How to auto suggest rich contents while searching in Google AMP?


   
Copy after login

in conclusion

In this post, we learned about what is Google AMP and we use it to use different scripts in Google AMP like "amp-autocomplete", "amp-form", "amp-mustache" and "amp-project") to automatically suggest rich content.

The above is the detailed content of How to automatically provide rich content suggestions when searching in Google AMP?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template