Useful Keyword Modifiers

Last Updated: 05 Jul 2019

Below is a collection of examples of different ways keyword modifiers can be used. If you have a handy keyword modifier you would like to add to the list, be sure to let us know.

Word play

Print ellipsis symbol if a block of text exceeds maximum number of words or characters

//max characters
//max words

Max charcount result: The quick brown fox jumped over the lazy dog => The quick brown fox…

Max wordcount result: The quick brown fox jumped over the lazy dog => The quick brown fox jumped…

Print a semicolon separated list from a matrix value (such as checkbox, select field, multiple text metadata fields) into a ordered or un-ordered list, but only if it is not empty


Original: Value 1; Value 2; Value 3

Result: <ul><li>Value 1</li><li>Value 2</li><li>Value 3</li></ul>

Number play

Calculate 10% GST of a product price and price without GST

//price excluding GST

GST result: 110.00 => 10.00

Price excluding GST result: 110.00 => 100.00

Simple padding

Pad to two digits: Adds an extra '0' in front if the number is only one digit.


Regular Expression Replacements

Print the file extension of any file asset

%asset_name^replace:.*\.: %

Result: document.pdf => pdf

Extract any parameter value from a URL


Result: => 5B-Es5-CjFg

Print the page number outside of an asset listing, conditionally

%globals_server_QUERY_STRING^contains:_result_page:Page : %%globals_server_QUERY_STRING^replace:.*_result_page=:^replace:&.*:%

Result: => Page 2

Escape percentages from keyword value


Result: %some_matrix_keyword% => &#37;some_matrix_keyword&#37;

Replace all white space occurrences (including new lines) with a single space

%asset_metadata_description^replace:\s: %

Result: Some description
with line break => Some description with line break .

Or, to condense all white space:

%asset_metadata_description^replace:\s+: %

Strip HTML but retain spaces between paragraphs and line breaks

% asset_metadata_description^replace:(<\/p>|<br\/?>):\1 ^striphtml%

Result: Line 1.
Line 2. => Line 1. Line 2. . If necessary, cater for other elements like h[1-6]

Print your site path without the domain

<MySource_PRINT id_name="__global__" var="current_asset" keyword="asset_url^replace:((.)*\.\D{2,3}):/" />

This will take all characters up until it reaches a period character, followed by characters of length 2 to 3 ( , .net , etc) and replace them with the / character. Please note that if any of your webpages contain a period in the page directory (such as / ), this will not work.

Result: => /newpage/test-page

Print a schema relative path for an asset URL


Result => //

Remove certain parts of a URL (including colon)

This trick uses the hexadecimal representation of a character, in this case colon: "\x3A".

First group matches "http://" or "https://". Second group matches everything after the domain (first slash).


Using colon in a time stamp

Instead of having a separate keyword replacement for each part of the date format, use a different divider (eg =), then replace the url-encoded value.


Using colon in ^eq:: return value

Uses the base64 value for colon (Og==).


Return the first or last word (even if hyphenated) from a string

%asset_name%                   ==>  John-Paul Syriatowicz
%asset_name^replace:(\s).*$:%  ==>  John-Paul
%asset_name^replace:.*(\s):%   ==>  Syriatowicz

Remove the last or first character of a string

%asset_name%                               ==>  ABC
%asset_name^replace:.$:%                   ==>  AB
%asset_name^reverse^replace:.$:^reverse%   ==>  BC


Print different asset value depending on asset type (parse file example)

<MySource_PRINT var="asset_type^replace_keywords:contains:Redirect:{redirect_url}:{asset_url}" />

Redirect pages will print redirect_url keyword value.

All other pages will print asset_url keyword value.

List out current asset contents with it’s own paint layout

When using %asset_contents% keyword replacement in an asset listing, be sure to use the following to ensure it is painted with it’s own paint layout:

% asset_assetid^as_asset:asset_contents%

Output 'checked="checked"' if asset ID is in a comma-separated list of IDs

This one his handy if you need to store multiple asset IDs in a single metadata field, and then spit them out in a form

% globals_user_metadata_feed_subscriptions^replace_keywords:replace:.*\b{asset_assetid}\b.*:\1^replace_keywords:eq:{asset_assetid}:checked="checked"%

Use metadata of homepage if current page metadata is empty

Use case: Custom background images on children pages which are different to the home page. If not custom image set, use the homepage image.


Get current URL

If %globals_asset_url% isn't what you want, try one of:


Print dynamic value depending on if you are on the homepage or not

//Up to version

//From version and up:

Change the name of the commit button on Asset Builders

Change "Commit" to whatever the commit button's value is in your system.

%commit_button_clean^replace:Commit:Submit Comment%

The Latest

Let Us Know What You Think

Let us know if you spot any errors or if you have any ideas on how we can improve the Matrix Community Website.

Contact Squiz for Demo

Let us show you the true power of Squiz Matrix by giving you a personalised demonstration.