0

This code worked fine in Craft 2:

 {% set entries = craft.entries.section('events').relatedTo(category).orderBy('startDate asc').limit(3) %}
 {% set extraEntries = craft.entries.section('events').relatedTo(category).orderBy('startDate asc').offset(3) %}
 {% if extraEntries | length %}
    //do some stuff
 {% endif %}

In Craft 3, {{ extraEntries | length }} is giving a value a 1 even when there are no entries. For example, {% for e in extraEntries %}>>>{{e}}{%endfor%} doesn't output anything. Any thoughts?

1

Because extraEntries is not an array of elements but an object of type EntryQuery in order to fetch the entries you have to do

{% set extraEntries = craft.entries.section('events').relatedTo(category).orderBy('startDate asc').offset(3).all() %}

It was actually the same in Craft 2 but the class had an iterable and countable interface, so when you do |length it actually does .total() (to execute the command and fetch the number of rows) These automatic mechanisms are removed/deprecated now thus you have to know what kind of object you use

When you take a look at your cp you'll see a bunch of deprecated warnings.

I suggest you to read the docs

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.