Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{# Get the IDs of all the sections #}
{% set currentSectionId = entry.id %}
{% set allSectionIds = craft.entries.section('myStructure').level(1).ids() %}
{# Define var before loop #}
{% set sectionNumber = '' %}
{# Loop through all section IDs and find the one that matches the current #}
{% for key, sectionId in allSectionIds if sectionId == currentSectionId %}
{# Use array key to calculate the section's position #}
{% set sectionNumber = key + 1 %}
{% endfor %}
{# Credit: http://craftcms.stackexchange.com/questions/1779/display-number-based-on-position-in-structure-hierarchy/1781#1781 #}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.