Download the PHP package vedmant/laravel-shortcodes without Composer
On this page you can find all versions of the php package vedmant/laravel-shortcodes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vedmant/laravel-shortcodes
More information about vedmant/laravel-shortcodes
Files in vedmant/laravel-shortcodes
Package laravel-shortcodes
Short Description Wordress like shortcodes for Laravel
License MIT
Homepage https://github.com/vedmant/laravel-shortcodes
Informations about the package laravel-shortcodes
Laravel Shortcodes
Wordpress based Shortcodes for Laravel Framework with shared variables, debugbar integration, flexible configurations and other useful features.
Build powerful and simple layouts using shortcodes in the content or views like this:
Installation
Via Composer
Configuraton
Publish configuration.
It will publish configuration file shortcodes.php
, edit it as needed.
Usage
Shortcode class
Shortcode class should extend abstract \Vedmant\LaravelShortcodes\Shortcode class.
This packages adds the make:shortcode
artisan command:
Which generates a shortcode class in the app/Shortcodes
folder by default.
Register shortcodes
You can use AppServiceProvider::boot
method to register all needed shortcodes.
Using shortcode class:
Using shortcode classes in array, preferable for lots of shortcodes:
Using closure:
Render shortcodes
Views auto-render
By default this package extends the View
class to parse all shortcodes during views rendering.
This feature can be disabled in the config file: 'render_views' => false
.
For better performance with lots of views it's advised to disable views auto-render.
Enable / disable rendering per view
Also to enable / disable rendering shortcodes for a specific view you can use:
Render shortcodes with the facade
Render shortcodes with blade directive
Render shortcodes with shortcodes()
helper
Shared attributes
Occasionally, you may need to share a piece of data with all shortcodes that are rendered by your application.
You may do so using the shortode facade's share
method.
Typically, you should place calls to share in the controller, or within a service provider's boot method.
Then you can get shared attributes in the shortcode class:
Attribute casting
The $casts property on your shortcode class provides a convenient method of converting attributes to
common data types. The $casts property should be an array where the key is the name of the attribute
being cast and the value is the type you wish to cast the column to. The supported cast types are:
int
, integer
, real
, float
, double
, boolean
, array
(comma separated values) and date
.
Now the show_ids
attribute will always be cast to an array when you access it.
(array attributes are casted from comma separated string, eg. "1,2,3").
Attribute validation
There is a simple way to validate attributes. Error messages will be rendered on the shortcode place. For convenients it will return attributes.
Option to not throw exceptions from shortcodes
There is a useful option to aviod server (500) error for whole page when one of shortocode has thrown an exception.
To enable it set 'throw_exceptions' => false,
in the shortcodes.php
config file.
This will render exception details in the place of a shortcode and will not crash whole page request with 500 error. It will still log exception to a log file and report to Sentry if it's integrated.
Generate data for documentation
There can be hundreds of registered shortcodes and having a way to show documentation for all shortcodes is quite a good feature. There is simple method that will collect descriptions and attributes data from all registered shortcodes:
It returns Collection object with generated data that can be used to generate any help information.
Integration with Laravel Debugbar
This packages supports Laravel Debugbar
and adds a tab with detailed info about rendered shortcodes.
Integration can be disabled in the config file with option: 'debugbar' => false,
.
Testing
TODO
- Add custom widget for debugbar integration
- Create performance profile tests, optimize performance
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- All Contributors
License
MIT. Please see the license file for more information.
All versions of laravel-shortcodes with dependencies
illuminate/contracts Version >=5.5.0
illuminate/view Version >=5.5.0
illuminate/support Version >=5.5.0