Answer the question
In order to leave comments, you need to log in
How to write attributes into javascript assets in Yii2?
Hello.
--
There is an asset for the layout, it needs attributes:
<script src="vendor/pace.js/pace.js" data-pace-options='{ "target": ".content-wrap", "ghostTime": 1000 }'></script>
<script id="test" src="vendor/underscore/underscore.js"></script>
<?php
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* Main frontend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/application.min.css',
];
public $js = [
'js/defina.min.js', // нужно добавить id и data-...
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
...
function wpb_adding_scripts() {
wp_register_script('script-defina', get_template_directory_uri() . '/js/defina.min.js','','1.1', true);
wp_enqueue_script('script-defina');
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
...
...
public function init()
{
if (\yii::$app->request->url == '/video') {
$this->js[] = 'js/jquery.countdown.js', ['id' => 'test', 'data-pace-options' => '{ "target": ".content-wrap", "ghostTime": 1000 }'];
$this->js[] = 'js/script.time.js';
}
}
...
Answer the question
In order to leave comments, you need to log in
https://www.yiiframework.com/doc/api/2.0/yii-web-a...
public $js = [
'js/defina.min.js' => ['data-pace-options'=>'{ "target": ".content-wrap", "ghostTime": 1000 }']
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question