Documentation
Feedback
Guides
Learning Center

Learning Center
Learning Center
Block's Carousel
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

Slider Layout, like Flex Layout, is a flexible way to create a new block from other blocks using children. It allows sliders to be created from other blocks, such as info-cards and even flex-layout for example.

With the Slider Layout, it is possible to create a carousel not only with images but with any content you want. For this example, we will use the Slider Layout to turn a set of info-cards into a slider.

Slider Layout

Looking at the documentation, we see that you can use an array of blocks like children, just like in Flex Layout.

Below is an example of implementing a slider-layout with two info-cards:


_30
_30
"slider-layout#home": {
_30
"children": ["info-card#1", "info-card#2"],
_30
"props": {
_30
"autoplay": {
_30
"timeout": 5000,
_30
"stopOnHover": false
_30
}
_30
}
_30
},
_30
_30
"info-card#1": {
_30
"props": {
_30
"imageUrl": "https://images.unsplash.com/photo-1524185962737-ea7c028a12cd?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80",
_30
"isFullModeStyle": true,
_30
"headline": "Black Friday",
_30
"callToActionText": "Subscribe",
_30
"textPosition": "center"
_30
}
_30
},
_30
_30
"info-card#2": {
_30
"props": {
_30
"imageUrl": "https://images.unsplash.com/photo-1524185962737-ea7c028a12cd?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80",
_30
"isFullModeStyle": true,
_30
"headline": "Black Friday",
_30
"callToActionText": "Subscribe",
_30
"textPosition": "center"
_30
}
_30
}

Activity

In this activity, we will create a brand slider for our website:

{"base64":"  ","img":{"width":1278,"height":154,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":10885,"url":"https://appliancetheme.vteximg.com.br/arquivos/brand-slider.png"}}

  1. In the home.jsonc file, declare the slider-layout#home block to the store.home template.

  2. Create a file called slider-layout.jsonc inside the/store/blocks folder;

  3. In this file, based on the code above, replace the info-card declared as children of slider-layout#home and add 6 image components image as children. Use the format image# brand1, image#brand2 (...) image#brand6 to declare the components;

  4. State a specific src prop for each defined image#brand. Use the URLs below for each one:

    1. https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square1.png
    2. https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square2.png
    3. https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square3.png
    4. https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square4.png
    5. https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square5.png
    6. https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square6.png
  5. Finally, you must use the autoplay property in the slider-layout# home block. Make slide happen automatically every 7 seconds and stop when the user hovers over _slide _.

Note: Remember to access the Slider Layout and Image documentations if you have any questions during the activity.


Answer sheet

See answer sheet for home.jsonc
home.jsonc

_12
{
_12
"store.home": {
_12
"blocks": [
_12
"rich-text",
_12
"info-card#button-right",
_12
"info-card#button-left",
_12
"flex-layout.row",
_12
"slider-layout#home"
_12
]
_12
}
_12
//...,
_12
}

See answer sheet for slider-layout.jsonc
slider-layout.jsonc

_48
{
_48
"slider-layout#home": {
_48
"children": [
_48
"image#brand1",
_48
"image#brand2",
_48
"image#brand3",
_48
"image#brand4",
_48
"image#brand5",
_48
"image#brand6"
_48
],
_48
"props": {
_48
"autoplay": {
_48
"timeout": 7000,
_48
"stopOnHover": true
_48
}
_48
}
_48
},
_48
"image#brand1": {
_48
"props": {
_48
"src": "https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square1.png"
_48
}
_48
},
_48
"image#brand2": {
_48
"props": {
_48
"src": "https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square2.png"
_48
}
_48
},
_48
"image#brand3": {
_48
"props": {
_48
"src": "https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square3.png"
_48
}
_48
},
_48
"image#brand4": {
_48
"props": {
_48
"src": "https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square4.png"
_48
}
_48
},
_48
"image#brand5": {
_48
"props": {
_48
"src": "https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square5.png"
_48
}
_48
},
_48
"image#brand6": {
_48
"props": {
_48
"src": "https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square6.png"
_48
}
_48
}
_48
}

On this page