2017 © Pedro Peláez
 

library shortcodes

Wordpress like shortcodes for Laravel 4.2

image

brouwers/shortcodes

Wordpress like shortcodes for Laravel 4.2

  • Thursday, March 26, 2015
  • by patrickbrouwers
  • Repository
  • 1 Watchers
  • 16 Stars
  • 7,631 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 5 Versions
  • 8 % Grown

The README.md

Laravel-Shortcodes

Wordpress like shortcodes for Laravel 4.2., (*1)

[b class="bold"]Bold text[/b]

[tabs]
  [tab]Tab 1[/tab]
  [tab]Tab 2[/tab]
[/tabs]

[user id="1" display="name"]

If you are looking for BBcodes, see: https://github.com/patrickbrouwers/Laravel-BBcodes, (*2)

Build Status Latest Stable Version Total Downloads License Monthly Downloads Daily Downloads, (*3)

Installation

Require this package in your composer.json and update composer., (*4)

"brouwers/shortcodes": "1.*"

After updating composer, add the ServiceProvider to the providers array in app/config/app.php, (*5)

'Brouwers\Shortcodes\ShortcodesServiceProvider',

You can use the facade for shorter code. Add this to your aliases:, (*6)

'Shortcode' => 'Brouwers\Shortcodes\Facades\Shortcode',

The class is bound to the ioC as shortcode, (*7)

$shortcode = App::make('shortcode');

Usage

View compiling

By default shortcode compiling is set to false inside the config., (*8)

withShortcodes()

To enable the view compiling features:, (*9)

return View::make('view')->withShortcodes();

This will enable shortcode rendering for that view only., (*10)

Config

Enabeling the shortcodes through config shortcodes::enabled will enable shortcoding rendering for all views., (*11)

Enable through class

Shortcode::enable();

Disable through class

Shortcode::disable();

Disabeling some views from shortcode compiling

With the config set to true, you can disable the compiling per view., (*12)

return View::make('view')->withoutShortcodes();

Default compiling

To use default compiling:, (*13)

Shortcode::compile($contents);

Registering new shortcodes

Inside a file or service provider you can register the shortcodes. (E.g. app/start/shortcodes.php or App/Services/ShortcodeServiceProvider.php), (*14)

Callback

Shortcodes can be registered like Laravel macro's with a callback:, (*15)

Shortcode::register('b', function($shortcode, $content, $compiler, $name)
{
  return '<strong class="'. $shortcode->class .'">' . $content . '</strong>';
});

Default class

class BoldShortcode {

  public function register($shortcode, $content, $compiler, $name)
  {
    return '<strong class="'. $shortcode->class .'">' . $content . '</strong>';
  }
}

Shortcode::register('b', 'BoldShortcode');

Class with custom method

class BoldShortcode {

  public function custom($shortcode, $content, $compiler, $name)
  {
    return '<strong class="'. $shortcode->class .'">' . $content . '</strong>';
  }
}

Shortcode::register('b', 'BoldShortcode@custom');

Register helpers

If you only want to show the html attribute when the attribute is provided in the shortcode, you can use $shortcode->get($attributeKey, $fallbackValue = null), (*16)

class BoldShortcode {

  public function register($shortcode, $content, $compiler, $name)
  {
    return '<strong '. $shortcode->get('class', 'default') .'>' . $content . '</strong>';
  }
}


The Versions

26/03 2015

dev-master

9999999-dev

Wordpress like shortcodes for Laravel 4.2

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0

 

The Development Requires

by Patrick Brouwers

wordpress laravel shortcodes

06/12 2014

1.0.2

1.0.2.0

Wordpress like shortcodes for Laravel 4.2

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0

 

The Development Requires

by Patrick Brouwers

wordpress laravel shortcodes

13/07 2014

1.0.1

1.0.1.0

Wordpress like shortcodes for Laravel 4.2

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0

 

The Development Requires

by Patrick Brouwers

wordpress laravel shortcodes

12/07 2014

1.0.x-dev

1.0.9999999.9999999-dev

Wordpress like shortcodes for Laravel 4.2

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0

 

The Development Requires

by Patrick Brouwers

wordpress laravel shortcodes

12/07 2014

1.0.0

1.0.0.0

Wordpress like shortcodes for Laravel 4.2

  Sources   Download

LGPL

The Requires

  • php >=5.4.0

 

The Development Requires

by Patrick Brouwers

wordpress laravel shortcodes