mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-01 11:39:41 +08:00
Fixes #13576: Added support of srcset to yii\helpers\Html::img()
This commit is contained in:
committed by
Alexander Makarov
parent
8e1a5eccde
commit
a26d28f8e3
@ -430,11 +430,22 @@ class BaseHtml
|
||||
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
|
||||
* If a value is null, the corresponding attribute will not be rendered.
|
||||
* See [[renderTagAttributes()]] for details on how attributes are being rendered.
|
||||
* @since 2.0.12 It is possible to pass the "srcset" option as an array which keys are
|
||||
* descriptors and values are URLs. All URLs will be processed by [[Url::to()]].
|
||||
* @return string the generated image tag
|
||||
*/
|
||||
public static function img($src, $options = [])
|
||||
{
|
||||
$options['src'] = Url::to($src);
|
||||
|
||||
if (isset($options['srcset']) && is_array($options['srcset'])) {
|
||||
$srcset = [];
|
||||
foreach ($options['srcset'] as $descriptor => $url) {
|
||||
$srcset[] = Url::to($url) . ' ' . $descriptor;
|
||||
}
|
||||
$options['srcset'] = implode(',', $srcset);
|
||||
}
|
||||
|
||||
if (!isset($options['alt'])) {
|
||||
$options['alt'] = '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user