FROM CACHE - es_header

hacer un loop en el "schema"

elpre
Nuevo miembro
5 0 0

Buenas tardes,

He hecho en la página de colecciones la siguiente estructura:

item item item item

imagen    item item

item item item item

item item   imagen

 

Esto está funcionando sin problema. Para quien quiera verlo, lo he hecho así:

{% assign float_item_count = item_count | times: 1.0 %}
          {% assign row = float_item_count | divided_by: section.settings.grid_desktop_items_per_row | ceil %}
          

          {%- if section.settings.layout_mode == 'grid' -%}
            <div class="ProductList ProductList--grid ProductList--removeMargin Grid" data-mobile-count="{{ section.settings.grid_mobile_items_per_row }}" data-desktop-count="{{ section.settings.grid_desktop_items_per_row }}">

            {% assign flag = 0 %}
            {% assign counter = 0 %}
            {% assign primero = 0 %}

              {%- for product in collection.products limit: block.settings.grid_items_count -%}
                <div class="Grid__Cell 1/{{ section.settings.grid_mobile_items_per_row }}--phone 1/2--tablet 1/{{ section.settings.grid_desktop_items_per_row }}--lap-and-up item-{{ counter }}">
                  {%- include 'product-item', show_product_info: section.settings.show_product_info, show_vendor: section.settings.show_vendor, show_color_swatch: section.settings.show_color_swatch, show_labels: true -%}
                </div>

                  
                  {%- comment -%}cada 4 elementos tengo que añadir una imagen {% endcomment %}
                  {% if primero == 0 and counter == 3 and flag == 0 %}
                    <div class="Grid__Cell 1/2--phone 1/2--tablet 1/4--lap-and-up item-4 imagen_collection"><img src="{{ section.settings.image1 | img_url: '800x' }}" alt="">
                    {% assign flag = 1 %}
                    {% assign counter = 0 %}
                    {% assign primero = 1 %}
                    </div>
                  {% endif %}

                  {% if counter == 4 and flag == 0 %}
                    <div class="Grid__Cell 1/2--phone 1/2--tablet 1/4--lap-and-up item-4 imagen_collection"><img src="{{ section.settings.image2 | img_url: '800x' }}" alt="">
                    {% assign flag = 1 %}
                    {% assign counter = 0 %}
                    </div>
                  {% endif %}

                  {% comment %} cada 8 elementos tengo que añadir una imagen {% endcomment %}
                  {% if counter == 8 and flag == 1 %}
                    <div class="Grid__Cell 1/2--phone 1/2--tablet 1/4--lap-and-up item-4 imagen_collection"><img src="{{ section.settings.image3 | img_url: '800x' }}" alt="">
                    {% assign flag = 0 %}
                    {% assign counter = 0 %}
                    </div>
                  {% endif %}

                  {% assign counter = counter | plus: 1 %}

              {%- endfor -%}

            </div>

 

El problema lo tengo en que quiero controlar las imágenes mediante el schema. Para el schema he hecho esto (he quitado texto para el ejemplo).

{% schema %}
{
  "name": "Featured collections",
  "class": "shopify-section--bordered-2",
  "max_blocks": 2,
  "settings": [
    {
      "type": "image_picker",
      "id": "image1",
      "label": "Image",
      "info": "1120 x 1200px .jpg recommended"
    },
    {
      "type": "image_picker",
      "id": "image2",
      "label": "Image",
      "info": "1120 x 1200px .jpg recommended"
    },
    {
      "type": "image_picker",
      "id": "image3",
      "label": "Image",
      "info": "1120 x 1200px .jpg recommended"
    }
  ]
}
{% endschema %}

 

Como véis, creo tres imágenes y esas no tengo problemas en controlarlas. Pero si una colección tiene 33 items, deberían aparecer 5 imágenes y quiero poder controlar esas 5 imágenes.

El problema es que no todas las colecciones tienen el mismo número de imagenes.

En lo que he hecho, me aparecen las 5 imágenes pero la imagen 2 y la imagen 4 es la misma y la imagen 3 y la 5 son la misma.

Yo querría poder crear un loop en el "settings" del "schema" porque sé el número de imágenes que habrá ya que cada 2 filas, habrá una imagen entonces me gustaría poder tener en el "schema" algo así:

"settings": [
{
"type": "image_picker",
"id": "image[n_imagenes]",
"label": "Image",
"info": "1120 x 1200px .jpg recommended"
}

Espero que se me haya entendido

3 RESPUESTAS 3

JaviMata
Shopify Partner
51 3 13

y por que no las pones como blocks?

Javi Mata | Twitter @Javi_Mata
- ¿Te resultó útil mi respuesta? Dale Me gusta para hacérmelo saber.
- ¿Resolví tu pregunta? Dale a Aceptar como solución.
elpre
Nuevo miembro
5 0 0

Ya tengo dentro de un block el tipo "collection" y si no pongo otro, me tapa el anterior.

elpre
Nuevo miembro
5 0 0

Buenas tardes,

he hecho esto:

 

"blocks": [
    {
      "type": "image_collection",
      "name": "Image Collection",
      "settings": [
        {
          "type": "image_picker",
          "id": "image",
          "label": "Image",
          "info": "1120 x 1200px .jpg recommended"
        },
        {
          "type": "text",
          "id": "subheading",
          "label": "Sub-heading",
          "default": "Sub-heading"
        },
        {
          "type": "text",
          "id": "title",
          "label": "Heading",
          "default": "Heading"
        },
        {
          "type": "text",
          "id": "button_text",
          "label": "Button text",
          "default": "View products"
        },
        {
          "type": "url",
          "id": "button_link",
          "label": "Button link",
          "info": "If none is set, collection URL is used."
        }
      ]
    }
  ]

 

 

Lo que me gustaría es que se crease el número de imágenes que necesito todo el rato.

Es decir, cuando hago esto con el block tengo que ir añadiendo "Image Collection" pero quiero que se me cree ya de por si y luego poder manipularlos.

No se si me explico