Documentation
Feedback
Guides
Storefront Development

Storefront Development
Store Framework
Building pages
Creating a custom search results page

When creating a brand new landing page for your store's website, you can decide to promote in it certain products to increase their sales or even user interactions, creating then a custom search results page.

Even though custom pages do not have the needed context to fetch search data, since they are build from scratch, the search-result-layout.customQuery block from the Search Result app is able to specify which query should be performed in order to get and render the desired search results for your users.

Engage your users with specific products through an URL path! Check out the instructions below:

Step by step

In order to build a custom search results page for your store, you must understand how a search results page is built and works in the first place. Access the Search Result app documentation and learn more about the blocks exported by this app, including the search-result-layout.customQuery.

  1. Access your Store Theme app directory using whichever code editor you prefer.
  2. In the routes.json file, define a new path called store.custom#landing, as shown below:

_10
"store.custom#landing": {
_10
"path": "/landing"
_10
}

The value defined for path can and should be replaced according to what is most suitable for your store's scenario.

  1. In the blocks.jsonc folder, create a new file to store the new custom search results page blocks. The new file could be called search-landing.jsonc, for example.
  2. In the file, declare the new custom page template name, such as store.custom#landing. Notice that the name must match the one declared in step 2.
  3. In the template's block list, add any theme block you want to build your new custom page. But remember: the search-result-layout.customQuery block is mandatory in order to define how the search query should be fetched. For example:

_10
{
_10
"store.custom#landing": {
_10
"blocks": [
_10
"image#landingbanner",
_10
"search-result-layout.customQuery"
_10
]
_10
}
_10
}

You can learn how to use the search-result-layout.customQuery block in order to define how the search query data should be fetched accessing the 3rd step of the Search Result app documentation.

  1. Declare the blocks according to the search results custom page you wish to have. Below you can find an example of a custom search results template:

_72
{
_72
"store.custom#landing": {
_72
"blocks": ["image#landing", "search-result-layout.customQuery"]
_72
},
_72
"image#landing": {
_72
"props": {
_72
"minWidth": "100%",
_72
"src": "https://user-images.githubusercontent.com/18701182/69889938-64b16180-12d2-11ea-8d8a-e3089cbeaffd.png"
_72
}
_72
},
_72
"search-result-layout.customQuery": {
_72
"props": {
_72
"querySchema": {
_72
"orderByField": "OrderByReleaseDateDESC",
_72
"hideUnavailableItems": true,
_72
"maxItemsPerPage": 8,
_72
"queryField": "Blue Top Retro Camera",
_72
"mapField": "ft"
_72
}
_72
},
_72
"blocks": [
_72
"search-result-layout.desktop",
_72
"search-result-layout.mobile",
_72
"search-not-found-layout"
_72
]
_72
},
_72
"search-result-layout.desktop": {
_72
"children": [
_72
"breadcrumb.search",
_72
"search-title.v2",
_72
"flex-layout.row#top",
_72
"search-fetch-previous",
_72
"flex-layout.row#results",
_72
"search-fetch-more"
_72
],
_72
"props": {
_72
"pagination": "show-more",
_72
"preventRouteChange": true
_72
}
_72
},
_72
"flex-layout.row#top": {
_72
"children": [
_72
"total-products.v2",
_72
"order-by.v2"
_72
]
_72
},
_72
"flex-layout.row#results": {
_72
"children": [
_72
"flex-layout.col#filter",
_72
"flex-layout.col#search"
_72
]
_72
},
_72
"flex-layout.col#filter": {
_72
"props": {
_72
"width": "20%"
_72
},
_72
"children": [
_72
"filter-navigator.v3"
_72
]
_72
},
_72
"flex-layout.col#search": {
_72
"children": [
_72
"search-content"
_72
]
_72
},
_72
"search-content": {
_72
"blocks": ["gallery", "not-found"]
_72
},
_72
"gallery": {
_72
"blocks": ["product-summary.shelf"]
_72
}
_72
}

  1. Save the changes performed in your Store Theme app.
  2. Using your terminal, log in to your VTEX Account and create a new development workspace.
  3. Once logged into the desired account and workspace, link your Store Theme app in order to see your new custom page live.
  4. Access your store's website using the following format: {workspaceName}--{accountName}.myvtex.com/{pathName}. You should see your new page live.

If you are happy with the changes to your Store Theme, make your new theme content public. Up until this point, only you could see it in your development workspace. Access our documentation on making your theme content publicly available and follow the steps detailed there.

Contributors
2
Photo of the contributor
Photo of the contributor
+ 2 contributors
Was this helpful?
Yes
No
Suggest edits (Github)
Contributors
2
Photo of the contributor
Photo of the contributor
+ 2 contributors
On this page