Giter VIP home page Giter VIP logo

yii2-shortcodes's Introduction

yii2-shortcodes

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
    }

}

yii2-shortcodes's People

Contributors

tpoxa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-shortcodes's Issues

call_user_func() expects parameter 1 to be a valid callback, class 'app\components\widgets\lastPhoto' not found

Установил пакет.
В конфиг добавил -
'shortcodes' => [
'class' => 'tpoxa\shortcodes\Shortcode',
'callbacks' => [
'lastphotos' => ['app\components\widgets\lastPhoto', 'widget'],
'anothershortcode' => function ($attrs, $content, $tag) {

             },
        ],
    ],

класс lastPhoto определяется.
Но при вызове парсера - появляется ошиибка.
2014-10-22_15-39-22

Если закоментить строку с ошибкой - то контент выводится, правда без парсинга... Т.е. проблема именно в выделенных строках

Parsing as bb-code?

Можно ли добавить возможность парсинга шорткодов, типа bb-code
[spoiler] ...some content ... [/spoiler]
В статьях зачастую бывает очень полезно. (спойлеры, табы, faq и тп.)
Спасибо

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.