I’ve figured out how to get models into partialLoops using the setObjectKey method of the PartialLoop helper. What I’m wondering if there is a way to specify that specific partial loops use the model key and other ones don’t. Right now I think I have to do something like this:
// sets the object key for ALL partialLoops
$this->partialLoop()->setObjectKey("model");
// do the thing
echo $this->partialLoop("elements/recent-blog.phtml", $this->blogs);
// reset the object key so further partialLoops do NOT use the key
$this->partialLoop()->setObjectKey(null);
Any way around this?
Suggestion to NOT using setObjectKey() is plain wrong – provided code would certainly fail to work with array of objects. Straight from the manual:
So, if you don’t want your objects to be serialized, you have to use setObjectKey(). Since parial and partialLoop helpers are both accessible from controller and view (as any other view helper), I tend to enable object key globally, and switch it of in particular loop (re-enabling at the loop end). Extra typing for sure, but seems to work well.