All Projects → webwizo → Laravel Shortcodes

webwizo / Laravel Shortcodes

Licence: mit
Wordpress like shortcodes for Laravel 4.2, 5.x, 6.x, 7.x and 8.x

Projects that are alternatives of or similar to Laravel Shortcodes

Docksal
Unified, Docker 🐳 powered web development environment for macOS, Windows, and Linux
Stars: ✭ 505 (+241.22%)
Mutual labels:  wordpress, laravel
Corcel
Use WordPress backend with Laravel or any PHP application
Stars: ✭ 3,504 (+2267.57%)
Mutual labels:  wordpress, laravel
Ansipress
AnsiPress - Simple L(Linux) E(NGINX) M(MariaDB) P(PHP7) Shared Hosting Setup
Stars: ✭ 184 (+24.32%)
Mutual labels:  wordpress, laravel
Pilothouse
A command line app for managing a LEMP local development environment based on Docker.
Stars: ✭ 98 (-33.78%)
Mutual labels:  wordpress, laravel
Db Seeder
A database seeder app for MySQL
Stars: ✭ 77 (-47.97%)
Mutual labels:  wordpress, laravel
Ddev
DDEV-Local: a local PHP development environment system
Stars: ✭ 915 (+518.24%)
Mutual labels:  wordpress, laravel
Lando
A development tool for all your projects that is fast, easy, powerful and liberating
Stars: ✭ 3,142 (+2022.97%)
Mutual labels:  wordpress, laravel
Wl Bootstrap
Integrating Laravel into WordPress
Stars: ✭ 54 (-63.51%)
Mutual labels:  wordpress, laravel
Laravel Woocommerce
WooCommerce Rest API for Laravel
Stars: ✭ 86 (-41.89%)
Mutual labels:  wordpress, laravel
Laravel5 Woocommerce Api Client
Laravel 5 wrapper for the Woocommerce REST API
Stars: ✭ 113 (-23.65%)
Mutual labels:  wordpress, laravel
Laravel Emoji
😄 This package assist you in getting started with emoji easily.
Stars: ✭ 146 (-1.35%)
Mutual labels:  laravel
Speedy
🚄A Laravel Admin Package to create a website quickly
Stars: ✭ 146 (-1.35%)
Mutual labels:  laravel
Messager
A convenient way to handle messages between users in a simple way
Stars: ✭ 147 (-0.68%)
Mutual labels:  laravel
Wpbullet
A static code analysis for WordPress (and PHP)
Stars: ✭ 148 (+0%)
Mutual labels:  wordpress
React Laravel Boilerplate
A Laravel REST API backend with React/Redux, hot module reloading in development and route-level code splitting
Stars: ✭ 146 (-1.35%)
Mutual labels:  laravel
Grosir Obat
Sebuah sistem kasir dan manajemen produk obat untuk penjualan Grosir
Stars: ✭ 147 (-0.68%)
Mutual labels:  laravel
Laravel Nuxt Js
Build a SPA with Laravel and Nuxt.
Stars: ✭ 146 (-1.35%)
Mutual labels:  laravel
Flarum
Simple forum software for building great communities.
Stars: ✭ 12,190 (+8136.49%)
Mutual labels:  laravel
Sage
WordPress starter theme with a modern development workflow
Stars: ✭ 11,531 (+7691.22%)
Mutual labels:  wordpress
Docker Wordpress
WordPress container with Nginx 1.16 & PHP-FPM 7.3 based on Alpine Linux
Stars: ✭ 148 (+0%)
Mutual labels:  wordpress

Laravel-Shortcodes

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads StyleCI

WordPress 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

Install

Via Composer

$ composer require "webwizo/laravel-shortcodes:1.0.*"

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

Usage

Webwizo\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

$shortcode = app('shortcode');

Usage

withShortcodes()

To enable the view compiling features:

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

This will enable shortcode rendering for that view only.

Enable through class

Shortcode::enable();

Disable through class

Shortcode::disable();

Disabling some views from shortcode compiling

With the config set to true, you can disable the compiling per view.

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

Default compiling

To use default compiling:

Shortcode::compile($contents);

Strip shortcodes from rendered view.

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

Strip shortcode through class

Shortcode::strip($contents);

Registering new shortcodes

Create 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 config/app.php

Usage

App\Providers\ShortcodesServiceProvider::class,

Callback

Shortcodes 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\[email protected]');
    }
}

Default class for BoldShortcode

You can store each shortcode within their class app/Shortcodes/BoldShortcode.php

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 method

You can store each shortcode within their class app/Shortcodes/ItalicShortcode.php

namespace App\Shortcodes;

class ItalicShortcode {

  public function custom($shortcode, $content, $compiler, $name, $viewData)
  {
    return sprintf('<i class="%s">%s</i>', $shortcode->class, $content);
  }
  
}

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)

class BoldShortcode {

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

Change log

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

Support me

Buy Me A Coffee

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].