Skip to content

Instantly share code, notes, and snippets.

@mildlygeeky
Last active August 29, 2015 14:03
Show Gist options
  • Save mildlygeeky/6f8eeb28a10240cde5a0 to your computer and use it in GitHub Desktop.
Save mildlygeeky/6f8eeb28a10240cde5a0 to your computer and use it in GitHub Desktop.
Generating a menu for Matrix blocks in Craft CMS
{% for block in entry.bodyBlocks %}
{%- if loop.first %}<ul>{% endif %}
<li><a href="#bodyblock-{{ block.ownerId }}-{{ block.id }}">{{ block.blockName }}</a></li>
{%- if loop.first %}</ul>{% endif %}
{%- endfor %}
{%- for block in entry.bodyBlocks %}
<div class="hidden" id="#bodyblock-{{ block.ownerId }}-{{ block.id }}"></div>
{{- block.blockBody }}
{%- endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment