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:

-
In the
home.jsoncfile, declare theslider-layout#homeblock to thestore.hometemplate. -
Create a file called
slider-layout.jsoncinside the/store/blocksfolder; -
In this file, based on the code above, replace the
info-carddeclared as children ofslider-layout#homeand add 6 image componentsimageas children. Use the formatimage# brand1,image#brand2(...)image#brand6to declare the components; -
State a specific
srcprop for each definedimage#brand. Use the URLs below for each one:https://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square1.pnghttps://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square2.pnghttps://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square3.pnghttps://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square4.pnghttps://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square5.pnghttps://appliancetheme.vteximg.com.br/arquivos/flatflat-brand-logo-square6.png
-
Finally, you must use the
autoplayproperty in theslider-layout# homeblock. 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.