2017 © Pedro Peláez
 

library shortcode

image

ps24love/shortcode

  • Monday, June 2, 2014
  • by ps24love
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel 4 - Simple Shortcode

Installation

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)

Registering Shorcode

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');

Compile

$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);

License

This package is open-sourced software licensed under the MIT license, (*11)

The Versions

02/06 2014

dev-master

9999999-dev

  Sources   Download

The Requires

 

by Avatar ps24love