2

I have a structure set up like:

What we do (set as a structure)

  • 2nd level page A

    * 3rd level page A
    * 3rd level page A
    
  • 2nd level page B

    * 3rd level page B
    

I'm setting up breadcrumbs for this so it's

Home / What we do / 2nd level page A / 3rd level page A

This is what I have so far but I can't figure out how to get the entry section url working (what-we-do) which is set in the Entry Url format.

{% set crumbs = entry.ancestors|default([]) %}
{% if crumbs|length %}
<ul class="breadcrumbs">
    <li><a href="{{ siteUrl }}">Home</a></li>
    <li><a href="{{ NEED HELP }}"> {{ entry.section.name }}</a></li>
    {% for crumb in crumbs %}
        <li><a href="{{ crumb.url }}">{{ crumb.title }}</a></li>
    {% endfor %}
    <li>{{ entry.title }}</li>
</ul>
{% endif %}
4
  • 1
    What does entry.url give you? Commented Jul 21, 2016 at 16:12
  • The whole URL. I'm after the url that the structure adds to the level above the entry.
    – sarah3585
    Commented Jul 22, 2016 at 9:44
  • I'm not sure what you mean? Using {{ entry.url }} will link to the section name you output with {{ entry.section.name }}. Commented Jul 22, 2016 at 9:49
  • {{ entry.url }} gives you the url of the current entry. ie /what-we-do/2nd-level/3rd-level I need just the /what-we-do part for the breadcrumb
    – sarah3585
    Commented Jul 22, 2016 at 10:47

1 Answer 1

3

I think you've made this more complicated that it needs to be for yourself. Reading the Craft docs on Outputting the Entry’s Ancestors in a Structure Section it looks like you can use the handle .getAncestors() method to output the entries leading up to the currently viewed entry automatically, and have access to their URLs.

Give the example a go.

{% if entry.level > 1 %}
  <ul class="crumbs">
    {% for crumb in entry.getAncestors() %}
      <li>{{ crumb.getLink() }}</li>
    {% endfor %}
  </ul>
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.