2017 © Pedro Peláez
 

library laravel-shortcodes

Laravel shortcodes package

image

gornymedia/laravel-shortcodes

Laravel shortcodes package

  • Saturday, October 7, 2017
  • by gornymedia
  • Repository
  • 2 Watchers
  • 9 Stars
  • 1,649 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 4 Versions
  • 21 % Grown

The README.md

Laravel-Shortcodes

Laravel Shortcodes Package, (*1)

Laravel compatibility

Laravel Shortcodes
12.x 1.5
11.x 1.5
10.x 1.4
9.x 1.4
8.x 1.4
7.x 1.4
6.x 1.4
5.8.x 1.3
5.5.x 1.2
5.4.x 1.1
5.3.x 1.1
5.2.x 1.1
5.1.x 1.0
5.0.x 1.0

Installation

Require this package with Composer, (*2)

composer require gornymedia/laravel-shortcodes 1.5

Add the service provider to bootstrap/providers.php, (*3)

Gornymedia\Shortcodes\ShortcodesServiceProvider::class,

To use the facades, add this within the register method of app/Providers/AppServiceProvider, (*4)

$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Shortcode', \Gornymedia\Shortcodes\Facades\Shortcode::class);

Copy the package config to your local config with the publish command, (*5)

php artisan vendor:publish --provider="Gornymedia\Shortcodes\ShortcodesServiceProvider"

Usage

Creating shortcodes

Inside an app/Providers/AppServiceProvider boot function you can create the shortcodes with attributes., (*6)

use Gornymedia\Shortcodes\Facades\Shortcode;

Shortcode::add('example', function($atts, $content, $name)
{
  $a = Shortcode::atts([
    'name' => $name,
    'foo' => 'something',
    ], $atts);

  return "foo = {$a['foo']}";
});

Usage : [example foo="something else"]

Include partial files in shortcode, (*7)

use Gornymedia\Shortcodes\Facades\Shortcode;

Shortcode::add('widget', function($atts, $content, $name) 
{
  $a = Shortcode::atts([
    'name' => $name,
    'foo' => 'something'
  ], $atts);

  $file = 'partials/' . $a['name'] ; // ex: resource/views/partials/ $atts['name'] .blade.php

  if (view()->exists($file)) {
    return view($file, $a);
  }
});

Usage : [widget name="maps"]

Compile shortcodes inside shortcode content, (*8)

use Gornymedia\Shortcodes\Facades\Shortcode;

Shortcode::add('strong', function($atts, $content, $name) {
 $content = Shortcode::compile($content);

 return "<strong>$content</strong>";
});

Usage: [strong][example][/strong]

View rendering

compileShortcodes()

To render the view and compile the Shortcodes:, (*9)

return view('view')->compileShortcodes();

stripShortcodes()

To render the view and remove the Shortcodes, (*10)

return view('view')->stripShortcodes();

In the config/gornymedia-laravel-shortcodes.php file you can set the default mode (null, compile or strip)., (*11)

The following example will compile shortcodes without using the compileShortcodes() method, (*12)

return [
    'mode' => 'compile'
];

License

This package is open-source software licensed under MIT License., (*13)

This package uses WordPress shortcodes methods. The license under which the WordPress software is released is the GPLv2 (or later)., (*14)

Support

Support me with any amount and help me develop., (*15)

, (*16)

The Versions

07/10 2017

dev-master

9999999-dev

Laravel shortcodes package

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Tom Gorny

laravel shortcodes

07/10 2017

v1.2

1.2.0.0

Laravel shortcodes package

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Tom Gorny

laravel shortcodes

27/03 2017

v1.1

1.1.0.0

Laravel shortcodes package

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Tom Gorny

laravel shortcodes

22/02 2015

v1.0

1.0.0.0

Laravel shortcodes package

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Tom Gorny

laravel shortcodes