Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 1.74 KB

templating.md

File metadata and controls

51 lines (40 loc) · 1.74 KB

Templating

Examples

Basic

<ol>
    {% for block in entry.neoField.level(1).all() %}
        {% switch block.type.handle %}
            {% case 'someBlockType' %}
                <li>
                    {{ block.someField }}
                    {% if block.children.all() is not empty %}
                        ...
                    {% endif %}
                </li>
            {% case ...
        {% endswitch %}
    {% endfor %}
</ol>

This is typically the most you'd need to know. Similar to how Matrix fields work, but with a notable difference. For Neo fields that have child blocks, you will first need to filter for blocks on the first level. It's essentially the same API as the craft.entries() element query.

Recursive

<ol>
    {% nav block in entry.neoField.all() %}
        <li>
            {{ block.someField }}
            {% ifchildren %}
                <ol>
                    {% children %}
                </ol>
            {% endifchildren %}
        </li>
    {% endnav %}
</ol>

Because Neo blocks have a level attribute, Neo fields are compatible with the {% nav %} tag.

craft.neo.blocks()

If you need to get Neo blocks in your template in a way that isn't connected to a Neo field value on a specific Craft element, you can use craft.neo.blocks(). This returns a Neo block query which can then be used in the same way as a typical Craft element query.

More information

For a more in-depth breakdown of templating for Neo, see this issue.