02/06
2014
Wallogit.com
2017 © Pedro Peláez
Open your composer.json file, and add the new required package., (*1)
"ps24love/shortcode": "dev-master"
Next, open a terminal and run., (*2)
composer update
After the composer updated. Add new service provider in app/config/app.php., (*3)
'ps24love\Shortcode\ShortcodeServiceProvider'
Add new Facade alias., (*4)
'Shortcode' => 'ps24love\Shortcode\Facades\Shortcode',
Done., (*5)
Using closure:, (*6)
Shortcode::register('a', function($attr, $content = null, $name = null)
{
$text = Shortcode::compile($content);
return '<a'.HTML::attributes($attr).'>'. $text .'</a>';
});
Using class name., (*7)
class DivShortcode { public function register($attr, $content = null, $name = null) { $text = Shortcode::compile($content); return ''. $text .''; } } Shortcode::register('div', 'DivShortcode');
Using class name with the specified method., (*8)
class HTMLShortcode { public function img($attr, $content = null, $name = null) { $src = array_get($attr, 'src'); $text = Shortcode::compile($content); return '<img src="'.$src.'" '.HTML::attributes($attr).'/>'; } } Shortcode::register('img', 'HTMLShortcode@img');
Using callback array., (*9)
class SpanShortcode { public function div($attr, $content = null, $name = null) { $text = Shortcode::compile($content); return '<span'.HTML::attributes($attr).'>'. $text .'</span>'; } } Shortcode::register('span', array('SpanShortcode', 'span'));
Using function name., (*10)
function smallTag($attr, $content = null, $name = null)
{
$text = Shortcode::compile($content);
return '<small'.HTML::attributes($attr).'>'. $text .'</small>';
}
Shortcode::register('small', 'smallTag');
$text = '[a href="#"]Click here[/a]'; echo Shortcode::compile($text); $text = ' [a href="#"] [img src="http://placehold.it/140x140"] [small]This is small text[/small] [/a] '; echo Shortcode::compile($text);
This package is open-sourced software licensed under the MIT license, (*11)