2017 © Pedro Peláez
 

yii2-extension shortcodes

Wordpress style shorttags support for Yii2

image

tpoxa/shortcodes

Wordpress style shorttags support for Yii2

  • Friday, October 20, 2017
  • by mtrofimenko
  • Repository
  • 5 Watchers
  • 19 Stars
  • 1,608 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 1 Versions
  • 8 % Grown

The README.md

yii2-shortcodes

Wordpress style shortcodes support for Yii2, (*1)

Most part of the code taken from https://github.com/Easy-Forex/WordPress-Shortcodes, (*2)

Installation

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

Configuration

In config file, (*3)

/config/main.php

Add shortcodes component, (*4)

'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('
some content [lastphotos limit=8] >
')

Additional

callbacks - An array of valid PHP callbacks. Keys should contain names of the shortcodes., (*5)

lastPhoto example class - common Yii2 widget, (*6)

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
    }

}

The Versions

20/10 2017

dev-master

9999999-dev

Wordpress style shorttags support for Yii2

  Sources   Download

Apache-2.0

by Maksym Trofimenko

yii2 shortcode