Commit 3048fdf6 by armab

Improve array support for "data" attribute in renderTagAttributes()

parent 66477091
......@@ -1569,6 +1569,8 @@ class BaseHtml
* the array will be "expanded" and a list data attributes will be rendered. For example,
* if `'data' => ['id' => 1, 'name' => 'yii']`, then this will be rendered:
* `data-id="1" data-name="yii"`.
* Additionally `'data' => ['params' => ['id' => 1, 'name' => 'yii'], 'status' => 'ok']` will be rendered as:
* `data-params='{"id":1,"name":"yii"}' data-status="ok"`.
*
* @param array $attributes attributes to be rendered. The attribute values will be HTML-encoded using [[encode()]].
* @return string the rendering result. If the attributes are not empty, they will be rendered
......@@ -1595,8 +1597,12 @@ class BaseHtml
}
} elseif (is_array($value) && $name === 'data') {
foreach ($value as $n => $v) {
if (is_array($v)) {
$html .= " $name-$n='" . Json::encode($v) . "'";
} else {
$html .= " $name-$n=\"" . static::encode($v) . '"';
}
}
} elseif ($value !== null) {
$html .= " $name=\"" . static::encode($value) . '"';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment