Agnostic Fetch
The code to fetch the elements from a Craft Element Query is different when the elements have been eager-loaded. For example, to get the first element of a non eagerly loaded field, someField.one()
, but for an eagerly loaded field, someField[0]
(and that doesn't even get into the error checking). With Agnostic Fetch, you can do someField | one
(or one(someField)
or craft.agnosticfetch.one(someField)
).
The Agnostic Fetch functions are available as twig filters, as twig functions, and as craft variables.
Free
Package Name
To install this plugin, search for its package name on the Plugin Store and click “Install”.