feature: macro n:attr expands arrays #158
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the first and only argument to n:attr macro is an array, expand it.
I opened another PR solving the same thing by adding a new macro here: #157
Motivation:
Suppose there is an array
$attributescontaining attributes for<meta>tag.The developer wants to achieve this HTML output:
However, using
<meta n:attr="$meta">the actual output is:The developer is currently forced to use workarounds, like:
{=Nette\Utils\Html::el('meta', $attributes)}The solution:
The
n:attrmacro be changed to expand the input array in case that:Code:
'$_tmp = %node.array; echo LR\Filters::htmlAttributes( isset($_tmp[0]) && is_array($_tmp[0]) && count($_tmp) === 1 ? $_tmp[0] : $_tmp);'After the proposed change, the developer can use
with an expected result.
Caveat:
This change may actually lead to a changed behaviour if in an IMHO rare case someone actually wanted to output something like
<tag 0="foo:bar">passing the array directly to the macro likeSidenote:
In this case, the macro is used for outputting metas:
This approach is however very useful for many other cases during output generation.