WordPress style shorttags support for Yii2

WordPress style shorttags support for Yii2

README

WordPress style shortcodes support for Yii2

Most part of the code taken from https://github.com/Easy-Forex/WordPress-Shortcodes

Installation

{
	"require": {
  		"tpoxa/shortcodes": "dev-master"
	}
}

Configuration

In config file

/config/main.php

Add shortcodes component

'components' => array(
        ...
        'shortcodes' => [
            'class' => 'tpoxashortcodesShortcode',
            'callbacks' => [
                'lastphotos' => ['frontendwidgetslastPhotolastPhoto', 'widget'],
                'anothershortcode'=>function($attrs, $content, $tag){
                ///
                },
                
            ]
        ],

Usage


echo Yii::$app->shortcodes->parse('
            <div><b>some content</b>  [lastphotos limit=8]  ></div>
    ')

Additional

callbacks – An array of valid PHP callbacks. Keys should contain names of the shortcodes.

lastPhoto example class – common Yii2 widget

namespace frontendwidgetslastPhoto; // your App class

use yiibaseWidget;
class lastPhoto extends Widget {

    public $limit = 5; // this parameter will be overwritten by 8 

    public function run() {
        // your widget content goes here
    }

}

Source

Add a Comment

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *