PHP code example of taylorpmt / short-code

1. Go to this page and download the library: Download taylorpmt/short-code 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/ */

    

taylorpmt / short-code example snippets


Taylorpmt\ShortCode\Providers\ShortcodesServiceProvider::class

'Shortcode' => Taylorpmt\ShortCode\Facades\Shortcode::class,



namespace App\Providers;

use Taylorpmt\ShortCode\Facades\Shortcode;
use Taylorpmt\ShortCode\Providers\ShortcodesServiceProvider;
use Illuminate\Foundation\AliasLoader;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {   
        $this->app->register(ShortcodesServiceProvider::class);
        $loader = AliasLoader::getInstance();
        $loader->alias('Shortcode', Shortcode::class);
    }

}




namespace CMS\Page\Repository\Shortcode;


class BlockSingleShortCode
{
    const short_code_name = 'category-item';

    /*
        Shortcode register in providers 
    */
    public function register($shortcode, $content, $compiler, $name, $viewData)
    {
       // Logic code 
    }
}



namespace CMS\Page\Providers;

use Illuminate\Support\ServiceProvider;
use Shortcode;
use CMS\Page\Repository\Shortcode\BlockSingleShortCode;

class PageProviders extends ServiceProvider
{
    public function register()
    {
        Shortcode::register(BlockSingleShortCode::short_code_name, BlockSingleShortCode::class);
    }
}


public function getDataContentAttribute()
{
    return Shortcode::compile($data['data_content']);
}