1

Editing an index page that displays all entries within a structure.

Everything displays fine.

I add a category to a few entries and add {% if category | length %}and everything disappears as if no entries had a category.

I get no twig errors, so I presume my code is okay.

Here it is, just in case:

          {% set entries = craft.entries.section('fellows').relatedTo(category) %}
      {% if category | length %}
        {% if entries | length %}
          {% for entry in entries %}
            {% for matrixBlock in entry.fellowsEntry %}
              {% if matrixBlock.type == 'entryContent' %}

                <a href="{{ entry.url }}" class="portfolio-view bio"> 
                    <div class="portfolio-index inner bio m-white col-md-12">
                        {% for image in matrixBlock.fellowImage %} 
                           <img src="{{ image.getUrl('sq300x300') }} " alt="" class="image-portfolio">
                         {% endfor %} 
                        <h3 class="name text-center p22-ltp">{{ entry.title }}</h3>
                        <hr>
                        <h3 class="org text-center p22-ltp">{{ matrixBlock.organization }} </h3>
                        <hr>
                        {{ category }}
                    </div></a> 

             {% endif %}
          {% endfor %} 
        {% endfor %}   
      {% endif %}
    {% endif %}
3
  • Are you setting category somewhere? Apr 13 '18 at 0:34
  • My understanding was that I am already in a category page and should have access to the {{ category }} model without having to set it. Apr 16 '18 at 15:44
  • Ah yes good point. My bad... Apr 16 '18 at 15:46
1

My Category URL Formats was set-up incorrectly. Or rather, I needed to go to {handle}/{slug} to see the proper result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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