在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):webwizo/laravel-shortcodes开源软件地址(OpenSource Url):https://github.com/webwizo/laravel-shortcodes开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Laravel-ShortcodesWordPress like shortcodes for Laravel 5.x [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 Laravel 4.2, see: https://github.com/patrickbrouwers/Laravel-Shortcodes InstallVia Composer $ composer require "webwizo/laravel-shortcodes:1.0.*" After updating composer, add the ServiceProvider to the providers array in UsageWebwizo\Shortcodes\ShortcodesServiceProvider::class, You can use the facade for shorter code. Add this to your aliases: 'Shortcode' => Webwizo\Shortcodes\Facades\Shortcode::class, The class is bound to the ioC as $shortcode = app('shortcode'); UsagewithShortcodes()To enable the view compiling features: return view('view')->withShortcodes(); This will enable shortcode rendering for that view only. Enable through classShortcode::enable(); Disable through classShortcode::disable(); Disabling some views from shortcode compilingWith the config set to true, you can disable the compiling per view. return view('view')->withoutShortcodes(); Default compilingTo use default compiling: Shortcode::compile($contents); Strip shortcodes from rendered view.return view('view')->withStripShortcodes(); Strip shortcode through classShortcode::strip($contents); Registering new shortcodesCreate a new ServiceProvider where you can register all the shortcodes. php artisan make:provider ShortcodesServiceProvider After defining shortcodes, add the ServiceProvider to the providers array in UsageApp\Providers\ShortcodesServiceProvider::class, CallbackShortcodes can be registered within ShortcodesServiceProvider with a callback: php artisan make:provider ShortcodesServiceProvider ShortcodesServiceProvider.php Class File <?php namespace App\Providers;
use App\Shortcodes\BoldShortcode;
use Illuminate\Support\ServiceProvider;
use Shortcode;
class ShortcodesServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
Shortcode::register('b', BoldShortcode::class);
Shortcode::register('i', 'App\Shortcodes\ItalicShortcode@custom');
}
} Default class for BoldShortcodeYou can store each shortcode within their class namespace App\Shortcodes;
class BoldShortcode {
public function register($shortcode, $content, $compiler, $name, $viewData)
{
return sprintf('<strong class="%s">%s</strong>', $shortcode->class, $content);
}
} Class with custom methodYou can store each shortcode within their class namespace App\Shortcodes;
class ItalicShortcode {
public function custom($shortcode, $content, $compiler, $name, $viewData)
{
return sprintf('<i class="%s">%s</i>', $shortcode->class, $content);
}
} Register helpersIf you only want to show the html attribute when the attribute is provided in the shortcode, you can use class BoldShortcode {
public function register($shortcode, $content, $compiler, $name, $viewData)
{
return '<strong '. $shortcode->get('class', 'default') .'>' . $content . '</strong>';
}
} Change logPlease see CHANGELOG for more information what has changed recently. ContributingPlease see CONTRIBUTING and CONDUCT for details. SecurityIf you discover any security related issues, please email [email protected] instead of using the issue tracker. CreditsSupport meLicenseThe MIT License (MIT). Please see License File for more information. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论