-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Allow defining arguments for f:render with f:argument
This patch allows you to define arguments that get passed to f:render by using f:argument inside the tag contents. ```xml <f:render partial="Something"> <f:argument name="arg1">Special value for arg1 variable</f:argument> <f:argument name="arg2">Special value for arg2 variable</f:argument> </f:render> ``` Any argument specified with f:variable this way will override the argument of the same name if it was passed in the “arguments” array as well. The combined result will be used as variables for the sub-rendering call. References: #427
- Loading branch information
1 parent
60545b6
commit 76d9e55
Showing
5 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
namespace TYPO3Fluid\Fluid\ViewHelpers; | ||
|
||
/* | ||
* This file belongs to the package "TYPO3 Fluid". | ||
* See LICENSE.txt that was shipped with this package. | ||
*/ | ||
|
||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic; | ||
|
||
/** | ||
* Argument assigning ViewHelper | ||
* | ||
* Assigns an argument for a parent ViewHelper call when | ||
* the parent ViewHelper supports it. | ||
* | ||
* Alternative to declaring an array to pass as "arguments". | ||
* | ||
* Usages: | ||
* | ||
* <f:render partial="Foo"> | ||
* <f:argument name="arg1">Value1</f:argument> | ||
* <f:argument name="arg2">Value2</f:argument> | ||
* </f:render> | ||
* | ||
* Which is the equivalent of: | ||
* | ||
* <f:render partial="Foo" arguments="{arg1: 'Value1', arg2: 'Value2'}'" /> | ||
* | ||
* But has the benefit that writing ViewHelper expressions or | ||
* other more complex syntax becomes much easier because you | ||
* can use tag syntax (tag content becomes argument value). | ||
* | ||
* @api | ||
*/ | ||
class ArgumentViewHelper extends AbstractViewHelper | ||
{ | ||
use CompileWithContentArgumentAndRenderStatic; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function initializeArguments() | ||
{ | ||
$this->registerArgument('value', 'mixed', 'Value to assign. If not in arguments then taken from tag content'); | ||
$this->registerArgument('name', 'string', 'Name of variable to create', true); | ||
} | ||
|
||
/** | ||
* @param array $arguments | ||
* @param \Closure $renderChildrenClosure | ||
* @param RenderingContextInterface $renderingContext | ||
* @return null | ||
*/ | ||
public static function renderStatic( | ||
array $arguments, | ||
\Closure $renderChildrenClosure, | ||
RenderingContextInterface $renderingContext | ||
) { | ||
if ($delegateVariableProvider = $renderingContext->getViewHelperVariableContainer()->getTopmostDelegateVariableProvider()) { | ||
$delegateVariableProvider->add($arguments['name'], $renderChildrenClosure()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters