Display number based on position in structure hierarchy I'm stuck. For a new site I need to display numbers before the main h1 title and in the submenu's.

Example:


1 Home
2 About


01 history 
02 strategy (active page)
03 profile
etc. etc.



In the active page (strategy) the title needs to be 02 strategy.
So the number is based on the position inside the parent. If I reorder strategy to the first position, the number needs to be 1. 

Can someone help me please?

preview http://durk.com/example.png
What about using CSS for your numbers? (Yes, this answer makes your question sound a bit off-topic, sorry for that, hehe)

Mainmenu:

.mainNav {
  counter-reset: mainNav;
}
.mainNav-item {
  counter-increment: mainNav;
}
.mainNav-item::before {
  content: counter(mainNav) ". ";
}


Submenu (double digits):

.subNav {
  counter-reset: subNav;
}
.subNav-item {
  counter-increment: subNav;
}
.subNav-item::before {
  content: counter(subNav, decimal-leading-zero) ". ";
  color: gold;
}


.

Edit:

Misunderstood that &lt;h1&gt; problem at first. I don't think that there's a dedicated function in Craft to get the position in a structure.

But you can get the entry position like so. You have to get all the structure entries that are on the same structure level with a new ElementCriteriaModel (→ new DB Queries) and then you do a conditional to find the position of the current entry.

{# 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 %}

{# Save the section's position in a custom data attribute #}
&lt;h1 data-section-no="{{ sectionNumber }}"&gt;Test&lt;/h1&gt;


Use CSS to style your heading:

h1:before {
  content: attr(data-section-no) ". ";
}