access data that may or may not have been eager-loaded
To install MN Eager, follow these steps:
- Download & unzip the file and place the
mneager
directory into yourcraft/plugins
directory - Install plugin in the Craft Control Panel under Settings > Plugins
MN Eager works on Craft 2.4.x, Craft 2.5.x., and Craft 2.6.x
The code to fetch the elements from a Craft ElementCriteriaModel is different when the elements have been eager-loaded.
This plugin provides a uniform syntax for fetching elements whether or not they have been eager loaded.
The MN Eager functions are available as craft variables and as twig extensions.
Use any of:
craft.mneager.find(someField)
mnFind(someField)
someField | mnFind
Use any of:
craft.mneager.first(someField)
mnFirst(someField)
someField | mnFirst
Use any of:
craft.mneager.last(someField)
mnLast(someField)
someField | mnLast
Use any of:
craft.mneager.nth(someField, index)
mnNth(someField, index)
someField | mnNth(index)
Use any of:
craft.mneager.ids(someField)
mnIds(someField)
someField | mnIds
Use any of:
craft.mneager.total(someField)
mnTotal(someField)
someField | mnTotal
In addition to the fetching function, isEager
will tell you whether an ElementCriteriaModel has been eager loaded:
craft.mneager.isEager(someField)
isEager(someField)
someField | isEager
- Initial release
- added
last
,nth
,ids
,total
to round out the fetching functions. - added
isEager
- added twig filters and functions
Brought to you by Marion Newlevant