Documentation
Feedback
Guides
Learning Center

Learning Center
Learning Center
Search page
View in Portuguese
This content was migrated from the VTEX Learning Center and is no longer being actively maintained. For the most accurate and up-to-date information, please check the official documentation.

Introduction

{"base64":"  ","img":{"width":2492,"height":1542,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":1327882,"url":"https://user-images.githubusercontent.com/18701182/69843114-d6db6500-1244-11ea-82a7-b10880e2ed55.png"}}

We've just implemented our product page and are moving on to the search page. Both are similar in the sense that both have blocks that are unique in this context. We will explore this block in a disorderly fashion, for now, just to get an idea of its behavior.

Starting out with Search Layout

Same as other templates, store.search can also be flexible. To build a unique layout you'll need to use a block called search-result-layout.


_10
{
_10
"store.search": {
_10
"blocks": ["search-result-layout"]
_10
}
_10
}

The search-result-layout, in turn, must receive 3 other blocks:

  • search-result-layout.desktop
  • search-result-layout.mobile
  • search-not-found-layout

As you've already noticed, the first two define which layout will be displayed on desktop and mobile respectively, while the third defines the layout of the no results found search page.


_12
{
_12
"store.search": {
_12
"blocks": ["search-result-layout"]
_12
},
_12
"search-result-layout": {
_12
"blocks": [
_12
"search-result-layout.desktop",
_12
"search-result-layout.mobile",
_12
"search-not-found-layout"
_12
]
_12
}
_12
}

In the course, we'll focus on desktop layout implementation.

Search blocks

The search results documentation offers a good reference for blocks that can be used in a search context. This step will focus on highlighting the main ones:

  • Search breadcrumb (breadcrumb.search);
  • Search title (search-title.v2);
  • Total products found (total-products.v2);
  • Product ordering (order-by.v2);
  • Show more results button (search-fetch-more);
  • Show previous results button (search-fetch-previous);
  • Navigation filter (filter-navigator.v3);
  • Search results (search-content)

Although quite many, all these blocks are relatively simple and work very well without an express need to configure their props.

Activity

{"base64":"  ","img":{"width":3265,"height":3295,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":1279025,"url":"https://user-images.githubusercontent.com/18701182/69843046-7f3cf980-1244-11ea-8309-8a26071cd6f0.png"}}

Copy the code above in search.jsonc and define a search-result-layout.desktop having the following, in the order mentioned below:

  • breadcrumb.search;
  • search-title.v2;
  • total-products.v2;
  • order-by.v2;
  • search-fetch-previous;
  • search-content;
  • filter-navigator.v3;
  • search-fetch-more.

To do so, write a code similar to:


_15
...
_15
},
_15
"search-result-layout.desktop": {
_15
"children": [
_15
"breadcrumb.search",
_15
"search-title.v2",
_15
"total-products.v2",
_15
"order-by.v2",
_15
"search-fetch-previous",
_15
"search-content",
_15
"filter-navigator.v3",
_15
"search-fetch-more"
_15
]
_15
}
_15
...

Note: Remember to go through the Search Result documentation if you have any questions during the activity.

Answer sheet

See answer sheet for search.jsonc
search.jsonc

_25
// store/blocks/search.jsonc
_25
{
_25
"store.search": {
_25
"blocks": ["search-result-layout"]
_25
},
_25
"search-result-layout": {
_25
"blocks": [
_25
"search-result-layout.desktop",
_25
"search-result-layout.mobile",
_25
"search-not-found-layout"
_25
]
_25
},
_25
"search-result-layout.desktop": {
_25
"children": [
_25
"breadcrumb.search",
_25
"search-title.v2",
_25
"total-products.v2",
_25
"order-by.v2",
_25
"search-fetch-previous",
_25
"search-content",
_25
"filter-navigator.v3",
_25
"search-fetch-more"
_25
]
_25
}
_25
}

On this page