/yii2-shortcodes

Primary LanguagePHPMIT LicenseMIT

yii2-shortcodes

Build Status codecov PHP 5.6 PHP 7.0 PHP 7.1 PHP 7.2

Yii2 behavior for rendering widgets with WordPress style shortcodes.

Installation

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require alexeevdv/yii2-shortcodes "~0.1.0"

or add

"alexeevdv/yii2-shortcodes": "~0.1.0"

to the require section of your composer.json file.

Configuration

use alexeevdv\yii\shortcodes\ShortcodeBehavior;

//...
'components' => [
    //...
    'view' => [
        'as shortcodeBehavior' => ShortcodeBehavior::class,
        'map' => [
            'feedback' => \frontend\widgets\ContactForm::class,
            'gallery' => [ 
                'class' => \frontend\widgets\GalleryWidget::class,
                'theme' => 'dark',
            ],
        ],
    ],
    //...
],
//...

Usage

namespace frontend\widgets;

class GalleryWidget extends \yii\base\Widget
{
    public $id;
    
    public $theme;
    
    public function run()
    {
        // render your gallery here using $id and $theme
    }
}
//Anywhere in your layouts, views or rendered content:

[gallery id=413]