PHP code example of waltersilvacruz / laravel-shortcodes
1. Go to this page and download the library: Download waltersilvacruz/laravel-shortcodes library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
waltersilvacruz / laravel-shortcodes example snippets
[b class ="bold "]Bold text [/b ]
[tabs ]
[tab ]Tab 1[/tab ]
[tab ]Tab 2[/tab ]
[/tabs ]
[user id ="1" display ="name "]
Webwizo\Shortcodes\ShortcodesServiceProvider::class,
'Shortcode' => Webwizo\Shortcodes\Facades\Shortcode::class,
$shortcode = app('shortcode' );
return view('view' )->withShortcodes();
Shortcode::enable();
Shortcode::disable();
return view('view' )->withoutShortcodes();
Shortcode::compile($contents);
return view('view' )->withStripShortcodes();
Shortcode::strip($contents);
App\Providers\ShortcodesServiceProvider::class,
namespace App \Providers ;
use App \Shortcodes \BoldShortcode ;
use Illuminate \Support \ServiceProvider ;
use Shortcode ;
class ShortcodesServiceProvider extends ServiceProvider
{
public function boot ()
{
}
public function register ()
{
Shortcode::register('b' , BoldShortcode::class);
Shortcode::register('i' , 'App\Shortcodes\ItalicShortcode@custom' );
}
}
namespace App \Shortcodes ;
class BoldShortcode {
public function register ($shortcode, $content, $compiler, $name, $viewData)
{
return sprintf('<strong class="%s">%s</strong>' , $shortcode->class, $content);
}
}
namespace App \Shortcodes ;
class ItalicShortcode {
public function custom ($shortcode, $content, $compiler, $name, $viewData)
{
return sprintf('<i class="%s">%s</i>' , $shortcode->class, $content);
}
}
class BoldShortcode {
public function register ($shortcode, $content, $compiler, $name, $viewData)
{
return '<strong ' . $shortcode->get('class' , 'default' ) .'>' . $content . '</strong>' ;
}
}
bash
php artisan make:provider ShortcodesServiceProvider
bash
php artisan make:provider ShortcodesServiceProvider