-
Notifications
You must be signed in to change notification settings - Fork 2.5k
partialLoop/partial View Helper can not be nested when using setObjectKey #3758
Comments
@tylkomat i haven't tested the following, but because the execute is immediately, there shouldn't be any problems? $this->partial('module/view/header')->setObjectKey('myVar1'); //assigned to myVar1, because immediately execute
$this->partial('module/view/footer')->setObjectKey('myVar2'); //assignet to myVar2, because immediately execute Haven't ever used |
@ThaDafinser The thing is the ViewHelpers in general are shared instances. When you change the |
@tylkomat I understand that there is only one instance. But could you maybe provide a "use-case" there you need this to be seperated? |
@ThaDafinser Let's say I have my
to call another template. In
to call an offers template ( |
@tylkomat Try cloning the partialLoop view helper within your partial view script: $partialLoop = $this->plugin('partialLoop');
$cloned = clone $partialLoop;
$cloned->setObjectKey('offer');
echo $cloned('event/offer', $this->event->offers); That should work; if it doesn't, we'll need to add a |
@weierophinney this works partially, I can access |
@tylkomat Hmm.. Yes, for that to work, we'd need to pass the PartialLoop instance in as well. For that to work, we'd need a third argument to $partialLoop = $this->plugin('partialLoop');
$cloned = clone $partialLoop;
$cloned->setObjectKey('offer');
echo $cloned('event/offer', $this->event->offers, array('partialLoop' => $cloned));
// inside your partial:
$partialLoop = $this->partialLoop;
$count = $partialLoop->getPartialCounter(); Do either you or @ThaDafinser want to take a stab at this feature? |
@weierophinney @ThaDafinser This feature might not be as simple as it seems. I was exploring a little of what should be changed and it seems it is a lot. Maybe I'm wrong, but I see two options here.
Maybe I'm thinking too complicated here. |
@tylkomat Well, adding another optional parameter to We could make either Keep thinking, and if you come with any concrete ideas, feel free to create a PR so we can discuss them. |
Since I just encountered this problem I thought I'd chip in. As a user it's easy to get around this problem by saving the current objectKey to a temporary variable and restoring when you're done:
This could be implemented by the framework using a stack of That would of course cause a BC break for those relying on the A somewhat more complex idea is to use a nesting-level bound |
This is handled in #7093 |
…ename properties for better clarity
…aking scope emulation variables `private`
…$key` may be `null`
…$key` may be `null`
…ixed return type (`self`)
…ixed return type (`self`), leveraging parent class API
…emoving minor code duplication
…/++/+= 1 - s/--/-= 1
…aking nesting/unNesting API `private`
…efactoring `PartialLoop` `$values` extraction logic into its own private method
…dding `@group` annotation for newly introduced tests
…dding test for non-iterable data exception message
…etter exception message in case of non-iterable values given to the PartialLop helper
…dding test for non-iterable object data exception message
…endframework#3758-scope-object-key-in-nested-partialloop-calls' Close zendframework/zendframework#7093 Close zendframework/zendframework#3758
…endframework#3758-scope-object-key-in-nested-partialloop-calls' into develop Close zendframework/zendframework#7093 Close zendframework/zendframework#3758 Forward port zendframework/zendframework#7093 Forward port zendframework/zendframework#3758
Since always the same
partial(Loop)
instance is used, setting a new object key inside apartial(Loop)
overwrites also the current object key (because same instance). Maybe it is a better way to provide theobjectKey
as optional parameter for the__invoke
methods ofpartial
andpartialLoop
.The text was updated successfully, but these errors were encountered: