PHP code example of gornymedia / laravel-shortcodes
1. Go to this page and download the library: Download gornymedia/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');
/* Start to develop here. Best regards https://php-download.com/ */
gornymedia / laravel-shortcodes example snippets
Gornymedia\Shortcodes\ShortcodesServiceProvider::class,
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Shortcode', \Gornymedia\Shortcodes\Facades\Shortcode::class);
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"]
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"]
use Gornymedia\Shortcodes\Facades\Shortcode;
Shortcode::add('strong', function($atts, $content, $name) {
$content = Shortcode::compile($content);
return "<strong>$content</strong>";
});
Usage: [strong][example][/strong]
return view('view')->compileShortcodes();
return view('view')->stripShortcodes();
return [
'mode' => 'compile'
];
shell
php artisan vendor:publish --provider="Gornymedia\Shortcodes\ShortcodesServiceProvider"