1

I'm getting a deprecation error from not using .all() to query my elements:

Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.

This is usually very easy to fix because Craft normally tells you which template and line to add the .all() to. However, when looking at the origin, I see:

/Users/Me/Sites/Project/vendor/twig/twig/lib/Twig/Extension/Core.php:577

This is pointing to something in Twig's vendor library, which I obviously don't want to fix for updating reasons. Does anyone know what this is referring to in my templates?

  • This is really difficult to spot. You could take a look at the stack trace to spot at least the URL route so get to know the root template – Robin Schambach Jul 7 '18 at 15:05
  • I know the root template because I'm on the page and see the error in the debug toolbar. It happens on a couple of pages of mine, but I don't understand what it wants me to change in the template code. All my element queries have the .all() added. The error doesn't appear on all pages though, and I can't figure out what's different between the templates to cause the error in some instances but not others. – Ryan Jul 7 '18 at 16:57
  • I guess some of your ElementQueries are not executed otherwise the error would not appear. You can edit the source code and instead of creating a deprecated error you dump the Query so you can see what things are searched. Or you post your Twig so we can search for it. Besides that I don't know how we are supposed to help. It's like fishing without water – Robin Schambach Jul 7 '18 at 17:01
  • If it's any help: it is executed in a twig_array_merge function so likely you are trying to |merge a Query – Robin Schambach Jul 7 '18 at 17:09
2

I figured out the issue. I was trying to get a single image from a matrix block by block.image|first instead of block.image.one(). The code was in a macro that was used on several templates so those templates got this error.

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.