Answer the question
In order to leave comments, you need to log in
How to add additional attribute in css files connection in Yii2?
The task is this, there are several css-files, in one of the css-files there is a parameter: media="print" , without it the layout goes.
This is how I include my css files:
class AppAsset extends AssetBundle
{
public $sourcePath = '@frontend/modules/site/assets';
public $css = [
'http://fonts.googleapis.com/css?family=Patua+One|Montserrat|Open+Sans:400,700,600',
'/js/fancybox/jquery.fancybox8cbb.css?v=2.1.5',
'/js/mediaelement/mediaelementplayer.css',
'/css/settings_style.css',
'/css/style-print.css',
'/css/skin_style.css',
'/css/style.css',
'/css/color_cheme.css',
'/css/responsive.css',
];
...
<link href="http://fonts.googleapis.com/css?family=Patua+One|Montserrat|Open+Sans:400,700,600" rel="stylesheet">
<link href="/js/fancybox/jquery.fancybox8cbb.css?v=2.1.5" rel="stylesheet">
<link href="/js/mediaelement/mediaelementplayer.css" rel="stylesheet">
<link href="/css/settings_style.css" rel="stylesheet">
<link href="/css/style-print.css" rel="stylesheet">
<link href="/css/skin_style.css" rel="stylesheet">
<link href="/css/style.css" rel="stylesheet">
<link href="/css/color_cheme.css" rel="stylesheet">
<link href="/css/responsive.css" rel="stylesheet">
<link href="/css/style-print.css" rel="stylesheet">
<link href="/css/style-print.css" type="text/css" media="print" rel="stylesheet"/>
$this->registerCssFile('/css/style-print.css', [], 'media="print"');
in F:\OpenServer\domains\portf.ru\vendor\yiisoft\yii2\helpers\BaseHtml.php
Illegal string offset 'rel'
// показывая на такой вот код
* @see url()
*/
public static function cssFile($url, $options = [])
{
if (!isset($options['rel'])) {
$options['rel'] = 'stylesheet';
}
$options['href'] = static::url($url);
return static::tag('link', '', $options);
}
$this->registerCssFile('/css/style-print.css');
Answer the question
In order to leave comments, you need to log in
As for the bundle attributes, only options for the entire bundle are currently implemented, see the $cssOptions property.
Accordingly, either take it out to a separate asset with the establishment of a dependency, or manually, through registerCssFile.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question