1

Good Evening,

Please bear with me I'm very new to Craft 3. I'm getting deprecation errors when outputting information.

I'm trying to output a single entry from a section using the following:

{% for entry in craft.entries.section('homepage') %}{{ entry.richText }}{% endfor %}

It is giving me the following error:

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

2

In your example, for entry in craft.entries.section('homepage') is attempting to loop through homepage entries as though they're an array. In Craft CMS 3, this is now deprecated just like the error message is telling you.

That means you need to use .all() when querying entries, meaning...

{% for entry in craft.entries.section('homepage') %}

...becomes...

{% for entry in craft.entries.section('homepage').all() %}

Ryan Irelan produced a nice video about this and it's also covered explicitly in the Craft 3 docs. If you've worked with Craft 2 and you're just getting started with Craft 3, that Changes in Craft 3 guide is an excellent place to start.

| improve this answer | |
  • Perfect thank you Matt, im returning to craft after quite some time, so appreciate the heads up. Is there a quick guide for outputing images from an entry? – springboynick Feb 3 '19 at 22:12
  • It depends on how you've configured your Entries, and how you want to output that image. You'll probably want to take a look at the templating section of the Assets Fields docs, and if you're getting used to Craft again it might help more broadly to take a look at the Happy Lager demo site to see some common patterns in the context of a small site. – Matt Stein Feb 3 '19 at 22:19
  • Im using an Asset field called 'banner', within a section called 'homepage', I assumed id be able to call the url from it easily. i must be missing something – springboynick Feb 3 '19 at 22:25
  • That doesn't seem relevant to the question or answer here. If you're looking for examples, I still strongly recommend looking through the Happy Lager demo site I linked to. If you'd like to chat with someone this isn't the right place for that, but the Craft CMS Slack group is perfect: craftcms.com/community. Please consider asking clear questions here and staying on topic, and accepting answers (on any Stack Exchange site) that you find to be most helpful. – Matt Stein Feb 3 '19 at 22:27

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.