Yii2 slider is an extension with Owl Carousel 2.3.3 slider in it.
The slider has multilingual behaviour for title and description on each slide.
composer require tomaivanovtomov/yii2-revolution "^1.1.3"
'modules' => [
....
'user' => [
'class' => 'tomaivanovtomov\slider\Module',
],
....
],
php yii migrate/up --migrationPath=@vendor/tomaivanovtomov/yii2-slider/migrations
\tomaivanovtomov\revolution\Assets::register($this);
Image path is set to www.example.com/frontend/web
.
Call the widget and set the preferable options.
height
- height of the slider.
slides
- Images like an array of objects.
public static function getSliderImages()
{
return \tomaivanovtomov\slider\models\Slide::find()
->joinWith('translation')
->select(['slide.id', 'slideLang.title', 'slide.filename'])
->where('slideLang.language=:lang', [':lang' => Yii::$app->language])
->all();
}
echo \tomaivanovtomov\slider\widgets\Slider::widget([
'slides' => \tomaivanovtomov\slider\models\Slide::getSliderImages(),
'height' => 400,
'options' => [
'items' => 1
]
]);
All slider options can be seen at
https://owlcarousel2.github.io/OwlCarousel2/docs/api-options.html
'language-information' => [
'BG' => [
'title' => 'Български',
'extension' => 'bg',
],
'EN' => [
'title' => 'English',
'extension' => 'en',
],
],
'languageDefault' => 'bg'
This portion of code is linked with the multilingual model functionality. You can override the model and adapt it to your needs.