A versatile and easy-to-use shortcode manager for Laravel applications, offering a simple way to integrate and manage shortcodes within a Laravel project.
kfoobar/laravel-shortcode is a Laravel package for a versatile and easy-to-use shortcode manager for laravel applications, offering a simple way to integrate and manage shortcodes within a laravel project..
It currently has 0 GitHub stars and 56 downloads on Packagist (latest version v1.0.3).
Install it with composer require kfoobar/laravel-shortcode.
Discover more Laravel packages by kfoobar
or browse all Laravel packages to compare alternatives.
Last updated
A lightweight and flexible shortcode manager designed for Laravel 8–12.
Install the package using Composer:
composer require kfoobar/laravel-shortcode
Publish the configuration file to customize settings:
php artisan vendor:publish --tag=shortcode-config
Easily define custom shortcodes like this:
Shortcode::add('author', 'Joe Doe');
Use the shortcodes array in the config file to set default shortcodes:
'shortcodes' => [
'author' => 'John Doe',
],
Shortcode keys are automatically transformed: they are converted to uppercase and wrapped with a character defined in the wrapper setting of your config file. The default wrapper character is %.
Obtain parsed content with various options:
// Standard Parsing
Shortcode::render($content);
// Markdown Conversion
Shortcode::markdown($content);
// Text Parsing (Stripping HTML)
Shortcode::text($content);
Shortcode::render('%YEAR% will be awesome!'); // 2024 will be awesome!
Within Blade templates, use the @shortcode directive:
@shortcode($content)
Note: The Blade directive employs the render() method.
Utilize the HasShortcode trait for automatic shortcode parsing:
use KFoobar\Shortcode\Traits\HasShortcode;
class MyModel extends Model
{
use HasShortcode;
// Specify attributes for parsing or use '*' for all
protected $shortcodes = ['*'];
Automatic shortcode parsing is turned off by default to avoid conflicts with writing operations. This precaution ensures that routine create, update and delete actions proceed without unintentional interference from the shortcode processing mechanism.
$model = (new MyModel)->withShortcode();
Enable auto-parsing by default:
protected $shortcode = true;
Enable auto-parsing for specific routes:
protected $middlewareGroups = [
'web' => [
// other middleware
\KFoobar\Shortcode\Middlware\ApplyShortcode::class,
],
The middleware automatically excludes non-read requests, AJAX requests, and Laravel Nova requests.
These are the predefined shortcodes:
| Shortcode | Value | | ---------- | ------------------- | | %YEAR% | 2024 | | %MONTH% | January | | %WEEK% | 3 | | %DAY% | Monday | | %DATE% | 2024-01-01 | | %TIME% | 12:00 | | %DOMAIN% | project.test | | %APP-NAME% | Laravel | | %APP-URL% | http://project.test |
Your contributions are highly appreciated.
The MIT License (MIT). Please see License File for more information.