I'm getting a deprecation error about looping through element queries, but in my markup all my loops are being setup with the .all() method, so I'm struggling to find this.

And it's one that is coming up every time I clear my errors, so the CMS clearly still thinks it's an issue.

Deprecation error

  • Can you share what you see when you click on that "Stack Trace" link?
    – Brad Bell
    Jan 4 '19 at 22:27
  • Opening few lines: imgur.com/a/fB6Jpu5
    – Jay
    Jan 6 '19 at 17:02

If you look in the list of file paths in the stack trace there will be one or more files in the storage/runtime/compiled_templates directory. In this particular case there is storage/runtime/compiled_templates/1a/1a584296a...ccfb9.php under number 33 in the stack trace. (If you're using PhpStorm you can press shift twice and paste in the filename to find it quickly.)

This file contains a PHP class that Twig compiles when the template is first accessed, so that it doesn't need to parse through all the twig code converting it into PHP every time the template is accessed.

At the top of this file is a comment that contains the path of the actual twig template. If needed, you might be able to work out a bit more context by looking at code at the line number in the stack trace (it's the :43 for this one). There will be another comment above this line that will tell you the line number in the twig template.

There may also be some clues in the stack trace itself. For example, here (again number 33 in the stack trace) you have the line:

twig_array_merge([], craft\elements\db\CategoryQuery)

This suggests to me that you're using the |merge filter, on a craft.categories query without calling .all() on it first, which also makes sense given the deprecation notice.

  • This is great! I was calling a category based on the category parameter in the URL but wasn't calling .one().
    – Jay
    Jan 8 '19 at 12:03

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.