1

I might be over-engineering this a bit, but I'm looking for a clean way to set up my homepage, for as few database queries and maintaining a DRY setup. The homepage is:

  • Hero introduction
    • Fields in a homepage single.
  • News & Events
    • Simple blog-like query

And then the two parts I'm confused about. Both of these are pulled from other singles.

  • About Us summary
  • Membership info

Is it fine to just query these pages individually? It feels so over the top to do something like

{% set aboutQuery = craft.entries().section('about') %}
{% set aboutPage = aboutQuery.all() %}
{% for page in aboutPage %}
  <h1>{{ page.title }}</h2>
  <p>{{ page.summary }}</p>
{% endfor %}

I'm sure this is a fairly common setup, so I just want to know what other people do in cases like this.

3

Maybe it feels over the top, cause you could simplify your small request to something like this:

{% for page in craft.entries.section('about').all() %}
<h1>{{ page.title }}</h2>
<p>{{ page.summary }}</p>
{% endfor %}

Or, if you just want to get the title and the summary of that one single - you could archieve this via:

{% set aboutPage = craft.entries.section('about').one() %}
<h1>{{ aboutPage.title }}</h1>
<p>{{ aboutPage.summary }}</p>
| improve this answer | |
  • Perfect! Thanks for simplifying it for me! – tommysvr May 22 at 9:19

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.