2017 © Pedro Peláez
 

library shortcode

The Shortcode Component for creating shortcodes.

image

force/shortcode

The Shortcode Component for creating shortcodes.

  • Monday, April 23, 2018
  • by Awilum
  • Repository
  • 2 Watchers
  • 4 Stars
  • 254 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Shortcode Component

version MIT License, (*1)

The Shortcode Component is a simple regex based parser that allows you to replace simple bbcode-like tags within a HTMLText or HTMLVarchar field when rendered into a content., (*2)

Installation

composer require flextype-components/shortcode

Usage

use Flextype\Component\Shortcode\Shortcode;

Examples of shortcode tags:, (*3)

{{shortcode}}
{{shortcode parameter="value"}}

Example of escaping shortcodes:, (*4)

{{{shortcode}}}

Add new shortcode

Your shorcode function:, (*5)

function returnSiteUrl() {
   return 'http://example.org';
}

Add shortcode, (*6)

Shortcode::add('site_url', 'returnSiteUrl');

Add new shortcode with Variables

Your shorcode function:, (*7)

function foo($attributes) {
    // Extract attributes
    extract($attributes);

    // text
    if (isset($text)) $text = $text; else $text = '';

    // return
    return $text;
}

Add shortcode {foo text="Hello World"}, (*8)

Shortcode::add('foo', 'foo');

Usage:, (*9)

{foo text="Hello World"}

Result:, (*10)

Hello World

Add new shortcode with Variables and Content

Your shorcode function:, (*11)

function foo($attributes, $content) {
    // Extract attributes
    extract($attributes);

    // text
    if (isset($color)) $color = $color; else $color = 'black';

    // return
    return '<span style="color:'.$color.'">'.$content.'</span>';
}

Add shortcode {foo color="red"}, (*12)

Shortcode::add('foo', 'foo');

Usage:, (*13)

{foo color="red"}Hello World{/foo}

Result:, (*14)

<span style="color: red">Hello World</span>  

Check if a shortcode has been registered.

if (Shortcode::exists('foo')) {
    // do something...
}

Remove a specific registered shortcode.

Shortcode::delete('foo');

Remove all registered shortcodes.

Shortcode::clear();

Braces

The shortcode parser does not accept braces within attributes. Thus the following will fail:, (*15)

{foo attribute="{Some value}"}Hello World{/foo}

License

See LICENSE, (*16)

The Versions

23/04 2018

dev-master

9999999-dev https://github.com/flextype-components/shortcode

The Shortcode Component for creating shortcodes.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

parser shortcode force flextype

23/04 2018

v1.1.0

1.1.0.0 https://github.com/flextype-components/shortcode

The Shortcode Component for creating shortcodes.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

parser shortcode flextype

27/10 2015

v1.0.1

1.0.1.0 https://github.com/force-components/Shortcode/issues

The Shortcode class for creating shortcodes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

parser shortcode force