Mecha CMS

Mecha CMS blog and documentation.

Wildcard in Shortcode

Updated: Sunday, 07 August 2016

Applying wildcards in shortcodes.

Table of Content

Mecha provides default shortcode syntax with a support of some wildcard for creating simple shortcode data:

Code

WildcardDescription
%sAccept any values without line breaks.
%mAccept any values with/without line breaks.
%iAccept any integer numbers. Example: 1, 123.
%fAccept any float numbers. Example: 1, 123, .1, 0.1, 0.10
%bAccept any boolean values. Includes: TRUE, FALSE, YES, NO, Y, N, ON, OFF, true, false, yes, no, y, n, on, off, 1, 0, +, -.
%[foo,bar]Accept foo or bar.

Usage

Example shortcode:

{{html.%s id="%s"}}%m{{/html}}

Example shortcode value:

<$1 id="$2">$3</$1>

Example shortcode usage:

{{html.div id="foo"}}
abc
def
ghi
{{/html}}

Example shortcode output:

<div id="foo">
abc
def
ghi
</div>

Tip

WildcardDescription
%[foo,]Optional value. Accept foo or not at all.
%[%i,foo,bar]Accept any integer numbers or foo or bar.

To include comma in the option list, you can use \,

%[foo,bar,baz\,qux]

The code above will accept foo, bar or baz,qux.

Donation and Email Subscription