V
V
VitaliyKaliuzhyn2017-02-13 18:12:43
Yii
VitaliyKaliuzhyn, 2017-02-13 18:12:43

Condition for Assets in Yii2?

Good day.
Is there a variable, Yii::$app->language
how can I include scripts in assets based on what this variable returns? Without creating its own asset for each language,
that is, for "ru" to connect the script

'theme/assets/global/plugins/date/locales/dater.ru.min.js'

and for "en"
'theme/assets/global/plugins/date/locales/dater.en.min.js'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DieZz, 2017-02-13
@VitaliyKaliuzhyn

Use AssetBundle and init() method in it like this:

<?php

namespace app\assets;

use yii\web\AssetBundle;

class AppAsset extends AssetBundle
{
    public function init()
    {
        $format = 'theme/assets/global/plugins/date/locales/dater.%s.min.js';
        $this->js[] = sprintf($format, \Yii::$app->language);
    }
}

E
Evgeny, 2017-02-13
@Caravus

'theme/assets/global/plugins/date/locales/dater.' . Yii::$app->language . '.min.js'

?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question