2017 © Pedro Peláez
 

library yii-shortcode

image

tahiryasin/yii-shortcode

  • Tuesday, March 6, 2018
  • by tahiryasin
  • Repository
  • 1 Watchers
  • 4 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

yii-shortcode

Yii-shortcode is a component for the Yii PHP framework that provides ability to create WordPress like shortcodes., (*1)

Usage

Setup

Download the latest release from Yii extensions., (*2)

Unzip the component under protected/components and add the following to your application config:, (*3)

return array(
  'components' => array(
    'shortcode' => array(
        'class' => 'application.components.ShortCode',
     ),
  ...
  ...
  ),
);

protected/config/main.php, (*4)

Registring Shortcodes

You can register as many shortcodes as you want in base controller or in any custom controller:, (*5)

public function beforeAction($action)
  {
      Yii::app()->shortcode->add_shortcode('gallery', array($this, 'gallery_callback'));
      Yii::app()->shortcode->add_shortcode('caption', array($this, 'caption_callback'));
      return $action;
  }

protected/components/Controller.php, (*6)

function gallery_callback($atts)
  {
      return "<div id='gallery'>Gallery #{$atts['id']}</div>";
  }  
function caption_callback($atts, $content)
  {
      return '<span class="caption">' . $content . '</span>';
  }  

protected/controllers/SiteController.php, (*7)

Rendering ShortCode

$content = 'My Gallery: [gallery id="123"]';
echo Yii::app()->shortcode->parse($content);

The output would be: My Gallery: <div id="gallery">Gallery #123</div>, (*8)

$content= 'Hi, check out this caption: [caption]My Caption[/caption]';
echo Yii::app()->shortcode->parse($content);

The output would be: Hi, check out this caption: <span class="caption">My Caption</span>, (*9)

protected/views/site/index.php, (*10)

The Versions

06/03 2018

1.0

1.0.0.0

  Sources   Download

10/03 2017

dev-master

9999999-dev

Yii component that enables you to create WordPress like shortcodes.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Tahir Yasin