Skip to content

Instantly share code, notes, and snippets.

@markgoodyear
Created March 10, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markgoodyear/045c2cbe6a4f23ec0a65 to your computer and use it in GitHub Desktop.
Save markgoodyear/045c2cbe6a4f23ec0a65 to your computer and use it in GitHub Desktop.
{# 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