PATH:
home
/
letacommog
/
letaweb
/
admin
/
extensions
/
yii-shortcode
yii-shortcode ============= Yii-shortcode is a component for the [Yii PHP framework](http://www.yiiframework.com) that provides ability to create [WordPress](http://codex.wordpress.org/Shortcode) like shortcodes. ## Usage ### Setup Download the latest release from [Yii extensions](http://www.yiiframework.com/extension/yii-shortcode). Unzip the component under ***protected/extension*** and add the following to your application config: ```php return array( 'components' => array( 'shortcode' => array( 'class' => 'application.extensions.yii-shortcode.ShortCode', ), ... ... ), ); ``` ***protected/config/main.php*** ### Registring Shortcodes You can register as many shortcodes as you want in base controller or in any custom controller: ```php public function init() { Yii::app()->shortcode->add_shortcode('gallery', array($this, 'gallery_callback')); Yii::app()->shortcode->add_shortcode('caption', array($this, 'caption_callback')); return parent::init(); } public function processOutput($output) { return Yii::app()->shortcode->parse($output); } ``` ***protected/components/Controller.php*** ```php 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*** #### Output The return value of a shortcode handler function is inserted into the page in place of the shortcode macro. Remember to use return and not echo - anything that is echoed will be output to the browser, but it won't appear in the correct place on the page. When used like this: `[caption]My Caption[/caption]` The output would be: `<span class="caption">My Caption</span>`
[+]
..
[-] README.md
[edit]
[-] ShortCode.php
[edit]