Extending snippets property types

Currently, when defining snippet, there are only three property types - text (string), checkbox and dropdown. Right? What if… there will be for example yaml configuration for creating large logic snippets, like promoboxes, etc.

If you wish to create a simple boxes (for ex. with same fields) you currently need to create as many snippets as boxes you need. right? so, this way is realy repeatable and when you will to prepare some content for client, wrong use can damage output.

you have container and inside are boxes… in Static Pages you need to create a static div container and there put some snippets with boxes… client are not aware of that and removes container… layout was broken…

large repeatable contents (tabs, blocks, etc.) can be managed same way as repeatable form field, then, when you add funcionality to accept yaml form configuration for this kind of property type, this will be helfpull.

I believe you can already do something similar to what you’ve mentioned using the repeater field.

At the top of your static page layout, define a repeater variable that has a “groups” attribute that points to a YAML file, like so…

I’m not certain why, but I think you have to have a dummy hidden variable within the repeater.

{repeater name="blocks" tab="Blocks" prompt="Add block" groups="../themes/your-theme-name/meta/layouts/blocks.yaml" }
    {variable type="hidden" name="_dummy"}{/variable}

Then define your blocks in the YAML file. For example,

  name: Hero
  description: Full width image with title and subtitle overlayed
    # Define your fields here

  name: Content and image
  description: Rich editor field with responsive image on the right
    # Define fields for this block here

Then, back in your blocks’ layout file. Loop over the repeater and render the HTML depending on the block’s identifier…

I like to stick each block’s HTML in a partial, passing the block content to it, to keep the layout file cleaner

{% for block in blocks %}
    {% if block._group == "hero_block" %}
        {% partial 'blocks/hero_block.htm' block=block %}
    {% endif %}
    {% if block._group == "content_image_block" %}
        {% partial 'blocks/content_image_block.htm' block=block %}
    {% endif %}
{% endfor %}
1 Like

this is way more new for me :smiley:

1 Like