osenco/shortcodes

Wordpress-like shortcodes for Laravel

dev-master 2019-05-24 12:05 UTC

This package is auto-updated.

Last update: 2024-04-25 06:35:10 UTC


README

Wordpress-style shortcodes for Laravel

Installation

Via Composer

Install this package via composer.

composer require osenco/shortcodes

Usage

Register Shortcode

To register a shortcode, use the helper function shortcode()->add() in the constructor method of any Controller or model you want to use.

Pass the shortcode tag as the first argument, and an anonymous function as the second argument, e.g

\shortcode()->add('tag', function(){ return date('Y); });

Use Shortcode

Add a shortcode to your content, optionally adding arguments as follows:

[shortcode_tag] [shortcode_tag attr="attr1"]

Render Content

To output content with the shortcodes parsed, use the shortcode()->do()

Pass the content you want to output as the argument.

{!! shortcodes()->do($content) !!}