Documentation
Feedback
Guides
Learning Center

Learning Center
Learning Center
Building a custom search landing 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

In the previous step, we looked at creating a custom template. In scenarios involving promotions and commemorative dates, it's quite common to create special landing pages.

Custom searches

We saw that the search deduces what is needed from the given context. On a custom page however, the context doesn't exist and you need to state which query should be performed to get the results. All this is made possible by the search-result-layout.customQuery.

Query schema

The query schema is one of the custom query search result props that allows you to control the search that the landing page should run. To know more the query schema's possibilities, read through its documentation.

Creating a new landing page

  1. Define a new path (store.custom#landing) in routes.json;


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

  2. Create a new file called search-landing.jsonc in the blocks folder;

  3. Create a new custom template entitled store.custom#landing;

  4. Define the image block as one of this template's blocks. This block must have minWidth props of 100% and an image of your choosing:


    _11
    "store.custom#landing": {
    _11
    "blocks": [
    _11
    "image#landingbanner"
    _11
    ]
    _11
    },
    _11
    "image#landingbanner": {
    _11
    "props": {
    _11
    "src": "https://storecomponents.vteximg.com.br/arquivos/box.png",
    _11
    "minWidth": "100%"
    _11
    }
    _11
    },

  5. Add the search-result-layout.customQuery block:


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

  6. Define the search-result-layout.customQuery block as the querySchema prop that:

  • Sorts by latest release date;

  • Hides unavailable items;

  • Displays a max of 8 items per page;

  • Uses "Camera" as query.


    _11
    "search-result-layout.customQuery": {
    _11
    "props": {
    _11
    "querySchema": {
    _11
    "orderByField": "OrderByReleaseDateDESC",
    _11
    "hideUnavailableItems": true,
    _11
    "maxItemsPerPage": 8,
    _11
    "queryField": "Blue Top Retro Camera",
    _11
    "mapField": "ft"
    _11
    }
    _11
    }
    _11
    }

  1. At this point, you're probably not seeing the block on the landing page. This is due to the fact that we have not add a block to the search-result-layout.customQuery yet. Here are two possibilities:

    • In case of having already done the previous courses, you probably have already changed the search.jsonc file in this template that we're using, in order to use the flex layout concept. Having it already done, it's only necessary to add the following code lines to the search-landing.jsonc file:


      _19
      // store/blocks/search-landing.jsonc
      _19
      {
      _19
      ...
      _19
      "search-result-layout.customQuery": {
      _19
      "props": {
      _19
      "querySchema": {
      _19
      "orderByField": "OrderByReleaseDateDESC",
      _19
      "hideUnavailableItems": true,
      _19
      "maxItemsPerPage": 8,
      _19
      "queryField": "Camera",
      _19
      "mapField": "ft",
      _19
      "skusFilter": "ALL_AVAILABLE"
      _19
      }
      _19
      },
      _19
      + "blocks": [
      _19
      + "search-result-layout.desktop"
      _19
      + ]
      _19
      }
      _19
      }

    • In case of not having enrolled for the previous courses and the search.jsonc is empty, it's necessary to add blocks to it. To do that, you can use the code block below. After doing that, you'll only need to add the search-result-layout.desktop block to the blocks array of search-result-layout.customQuery, just as mentioned before.


      _41
      // store/blocks/search.jsonc
      _41
      {
      _41
      "store.search": {
      _41
      "blocks": ["search-result-layout"]
      _41
      },
      _41
      "search-result-layout": {
      _41
      "blocks": [
      _41
      "search-result-layout.desktop",
      _41
      "search-result-layout.mobile",
      _41
      "search-not-found-layout"
      _41
      ]
      _41
      },
      _41
      "search-result-layout.desktop": {
      _41
      "children": [
      _41
      "breadcrumb.search",
      _41
      "search-title.v2",
      _41
      "flex-layout.row#top",
      _41
      "search-fetch-previous",
      _41
      "flex-layout.row#results",
      _41
      "search-fetch-more"
      _41
      ],
      _41
      "props": {
      _41
      "pagination": "showMore"
      _41
      }
      _41
      },
      _41
      "flex-layout.row#top": {
      _41
      "children": ["total-products.v2", "order-by.v2"]
      _41
      },
      _41
      "flex-layout.row#results": {
      _41
      "children": ["flex-layout.col#filter", "flex-layout.col#search"]
      _41
      },
      _41
      "flex-layout.col#filter": {
      _41
      "props": {
      _41
      "width": "20%"
      _41
      },
      _41
      "children": ["filter-navigator.v3"]
      _41
      },
      _41
      "flex-layout.col#search": {
      _41
      "children": ["search-content"]
      _41
      }
      _41
      }

      In this case, please look at the added code to ensure you understand the relation between the blocks and their functions.

The expected result is:

{"base64":"  ","img":{"width":1920,"height":976,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":1319582,"url":"https://user-images.githubusercontent.com/19495917/90278827-7033c100-de3e-11ea-9083-4d7279312d7f.png"}}

Answer sheet

See answer sheet for routes.json
routes.json

_10
// store/routes.json
_10
{
_10
"store.custom#about-us": {
_10
"path": "/about-us"
_10
},
_10
"store.custom#landing": {
_10
"path": "/landing"
_10
}
_10
}

See answer sheet for search-landing.jsonc
search-landing.jsonc

_23
// store/blocks/search-landing.jsonc
_23
{
_23
"store.custom#landing": {
_23
"blocks": ["image#landingbanner", "search-result-layout.customQuery"]
_23
},
_23
"image#landingbanner": {
_23
"props": {
_23
"src": "https://storecomponents.vteximg.com.br/arquivos/box.png",
_23
"minWidth": "100%"
_23
}
_23
},
_23
"search-result-layout.customQuery": {
_23
"props": {
_23
"querySchema": {
_23
"orderByField": "OrderByReleaseDateDESC",
_23
"hideUnavailableItems": true,
_23
"maxItemsPerPage": 8,
_23
"queryField": "Blue Top Retro Camera",
_23
"mapField": "ft"
_23
}
_23
}
_23
}
_23
}

On this page