tpoxa / shortcodes
Wordpress style shorttags support for Yii2
Installs: 12 779
Dependents: 0
Suggesters: 0
Security: 0
Stars: 22
Watchers: 6
Forks: 12
Open Issues: 0
Type:yii2-extension
pkg:composer/tpoxa/shortcodes
This package is not auto-updated.
Last update: 2025-10-25 21:22:59 UTC
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' => 'tpoxa\shortcodes\Shortcode',
            'callbacks' => [
                'lastphotos' => ['frontend\widgets\lastPhoto\lastPhoto', '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 frontend\widgets\lastPhoto; // your App class use yii\base\Widget; class lastPhoto extends Widget { public $limit = 5; // this parameter will be overwritten by 8 public function run() { // your widget content goes here } }