Documentation
Feedback
Guides
Learning Center

Learning Center
Learning Center
Carrossel de blocos
View in English
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.

Introdução

O Slider Layout, como o Flex Layout, é uma forma flexível de criar um novo bloco a partir de outros blocos usando children. Ele permite que sejam criados sliders de outros blocos, como info-cards e até mesmo flex-layouts por exemplo.

Com o Slider Layout é possível criar um carrossel não só de imagens, como de qualquer conteúdo que se queira. Para este exemplo, vamos utilizar o Slider Layout para tornar um conjunto de info-cards em um slider.

Slider Layout

Analisando a documentação, vemos que você pode utilizar qualquer array de blocos como children, assim como no Flex Layout.

Abaixo, segue um exemplo de implementação de um slider-layout com dois info-card:


_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
}

Atividade

Nesta atividade, vamos criar um slider de marcas para o nosso site:

{"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. No arquivo home.jsonc, declare o bloco slider-layout#home ao template store.home.

  2. Crie um arquivo chamado slider-layout.jsonc dentro da pasta /store/blocks;

  3. Neste arquivo, baseando-se no código acima, substitua os info-card declarados como children de slider-layout#home e adicione 6 componentes de imagem image como children. Utilize o formato image#brand1, image#brand2 (...) image#brand6 para declarar os componentes;

  4. Declare uma prop src específica para cada image#brand definido. Utilize as URLs abaixo para cada uma delas:

    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. Por fim, você deve utilizar a propriedade de autoplay no bloco slider-layout#home. Faça com que o slide aconteça automaticamente a cada 7 segundos e que ele pare quando o usuário passar o mouse em cima do slide.

Note: Lembre-se de acessar a documentação do Slider Layout e Image caso tenha alguma dúvida durante a atividade.

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