I’ve been wrestling with a site from another developer (who will not be named). He seems to have a pretty solid grasp of PHP, and I had assumed that he also understood Craft well.
However, as I started to look at his templates, I came across code like this:
{% if
(entry.productDimensionsImage.one() or
entry.productSpecifications.one())
%}
I would have written it using count() instead of one(), or if I really needed the entry:
{% set prodDim = entry.productDimensionsImage.one() %}
{% set prodSpc = entry.productSpecifications.one() %}
{% if (prodDim and prodSpc) %}
My main concern is that the exact same queries are being used repeatedly throughout a single template; he’s going back to the database over and over again to check the same entry. Then, after he’s done so half a dozen times, then he finally sets it in a variable to loop through it.
So, is there something I’ve misunderstood? Is there a good reason to keep querying the database multiple times in a single template file?
TIA