Global Keyword Replacements

Last Updated: 04 Jan 2016

Global keyword replacements can be used within various assets in the system to show different information about the asset in the global context, the current site they are viewing or their user account if they are logged in. For example, to show the name of the page the user is currently viewing as a heading in your Design, you can use the global keyword replacement %globals_asset_name%.

Bookmarks

Asset

Keyword ReplacementInformation Shown
%globals_asset_<common_keyword>%Any Common Keyword of the asset in the globals context. For example, %globals_asset_name% will print the name of the asset in the globals context.
%globals_asset_<common_keyword>:<assetid>%Any Common Keyword of any asset in the system. For example, if we have an asset in our system with an asset ID of #100 the global keyword %globals_asset_name:100% will show the name of this asset.
%globals_asset_attribute_<attribute>%Any attribute of the asset in the globals context. For example, %globals_asset_attribute_title% shows the Title attribute of a File type asset the user is currently viewing. This global keyword replacement could then be used in a Design to show the title of the asset. If the title of the asset then changes, the Design will not need to be updated, as the global keyword replacement will source the information directly from the asset.
%globals_asset_attribute_<attribute>:<assetid>%Any attribute of any asset in the system. For example, if we have an Image asset in our system with an asset ID of #100 the global keyword %globals_asset_attribute_title:100% will show the title of this Image asset, while the global keyword %globals_asset_attribute_size:100% will show its file size.
%globals_asset_metadata_<fieldname>%Any metadata value of the asset in the globals context. For example, if you have a Title metadata field on your asset, %globals_asset_metadata_Title% will show the value of this field.
%globals_asset_metadata_<fieldname>:<assetid>%Any metadata value of any asset in the system. For example, %globals_asset_metadata_Title:100% will show the Title metadata value on asset #100.
%globals_asset_contents_paint_layout_id_<paint_layout_id>:<assetid>%The contents of any asset in the system with a specific Paint Layout applied where <paint_layout_id> is the asset ID of the Paint Layout and <assetid> is the asset with the contents to print.
%globals_asset_contents_paint_layout_name_<paint_layout_name>:<assetid>%The contents of any asset in the system with a specific Paint Layout applied where <paint_layout_name> is the user-defined name of the Paint Layout and <assetid> is the asset with the contents to print.

Site

Keyword ReplacementInformation Shown
%globals_site_<attribute>%Any attribute of the current Site asset. For example, %globals_site_name% shows the name of the Site the user is currently viewing. This global keyword replacement could then be used in a Design to show the name of the Site. If the name of the Site then changes, the Design will not need to be updated, as the global keyword replacement will source the information directly from the Site.
%globals_site_index_id%The asset ID of the Site asset's Index page asset. An asset ID of a Site can be appended to specify a specific Site asset to return the asset ID value from. For example, %globals_site_index_id:100% will return the asset ID of the Index page of the Site with the asset ID of 100.
%globals_site_not_found_id%The asset ID of the Site asset's Not Found page asset. An asset ID of a Site can be appended to specify a specific Site asset to return the asset ID value from.
%globals_site_archive_id%The asset ID of the Site asset's Archive page asset. An asset ID of a Site can be appended to specify a specific Site asset to return the asset ID value from.

User

If an asset is going to be viewed by a user who is logged into your Site, you can personalise the content through the use of global keyword replacements. For example, if the page you are creating can only be viewed by a member of your Site who has logged in, then you can personalise the page using their Attributes or Metadata.

For Attributes, the format of the global keyword replacement is:

%globals_user_attribute_<attribute>%

where <attribute> is any attribute available on the user account. Some examples include %globals_user_attribute_first_name% which prints the first name of the user and %globals_user_attribute_email% which prints the email address of the User asset.

For Metadata, the format of the global keyword replacement is:

%globals_user_metadata_<fieldname>%

where <fieldname> is the name of the metadata field you want to show. For example, if you have applied a Metadata Schema to a user account that contains the field Hobbies, you can show the value that has been entered into this field by using the global keyword replacement %globals_user_metadata_Hobbies%. You can place these keyword replacements within the content of an asset. Squiz Matrix will then replace these keyword replacements with the correct information from the user account.

ReplacementInformation Shown
%globals_user_assetid%The asset ID of the current user.
%globals_user_attribute_username%The username of the current user.
%globals_user_attribute_email%The email address of the current user. 
%globals_user_attribute_first_name%The first name of the current user.
%globals_user_attribute_last_name%The last name of the current user.
%globals_user_attribute_login_date%The date of the current user's last login.
%globals_user_attribute_login_ip%The user's IP address of the current user's last login.
%globals_user_is_logged_in%A boolean keyword that prints 1 if the current user is logged in, or 0 if they are not. You can use this in conditional keyword blocks to print dynamic content based on the user's login status:
%begin_globals_user_is_logged_in%
  <p>Welcome <strong>%globals_user_name%</strong></p> 
%else_globals%
  <p><a href="/_login">Click here to log in</a></p> 
%end_globals%
%globals_user_member_groups%An array string of the user group asset IDs the current user is a member of.
%globals_user_messages_inbox%An array object of the current user's internal message inbox.

By default, the max limit on the messages returned for these keywords is 100. A keyword parameter can be used to change the result limit, for example %globals_user_messages_inbox_10%. This would return the latest 10 messages from the user's inbox.
%globals_user_messages_sent%An array object of the current user's sent internal messages.
%globals_user_messages_trash%An array object of the current user's sent internal message trash.
%globals_user_sugar_<module_name> _id%The SugarCRM Record ID applied to the current user where <module_name>  is the name of the Module that the Record ID is stored against. For example, %globals_user_sugar_Contacts_id%.

System Maintenance

ReplacementInformation Shown
%globals_system_maintenance_mode%The current status of system maintenance mode.
Returns the string 'Disabled', 'Notify' or 'Enabled' depending on the current status.
%globals_system_maintenance_message_backend%The current message set for system maintenance mode for the Matrix backend. or the website (frontend). If system maintenance mode is set to 'Disabled', no message is displayed.
%globals_system_maintenance_message_frontend%The current message set for system maintenance mode for the website frontend. If system maintenance mode is set to 'Disabled', no message is displayed.

Server Variable

ReplacementInformation Shown
%globals_server_<variable> %A PHP server variable where <variable> is the PHP session variable that you want to return server information from (ref: PHP $_SERVER Manual).

For example, the global keyword replacement %globals_server_http_user_agent% will return the header of the current request (e.g. Mozilla/4.5 [en] (X11; U;Linux 2.2.9 i586 ) ). Please note that the server information available will vary depending on the setup of your web server.

Session Variable

ReplacementInformation Shown
%globals_session_<variable> %A Matrix session variable where <variable> is the name of the item you want to access in the Matrix session sandbox. This global keyword replacement can be used in conjunction with Triggers. For example, in a Trigger, you can set a session variable and then access it via this global keyword replacement. For more information about Triggers, refer to the Triggers manual

HTTP GET & POST Variables

When using these keywords and printing their values directly onto the frontend, it is strongly recommended to use them in conjunction with the ^htmlentities:ENT_HTML5Keyword Modifier so that Keywords within the values don't get replaced when printed on the front end.

ReplacementInformation Shown
%globals_get_<variable> %An HTTP GET variable of the current page request where <variable> is the name of the GET variable that you want to access. Only scalar variables can be used as global keyword replacements, arrays are not supported.

For example, if the current Matrix page is requested with "?foo=bar" in the URL, %globals_get_foo% would print "bar".  
%globals_get %An array object of all the GET variables of the current page request. You can use keyword modifiers such as ^as_url_string to convert the returned array data into a URL string value.
%globals_post_<variable> %An HTTP POST variable of the current page request where <variable> is the name of the POST variable that you want to access. Arrays are not supported.

For example, if the current page is submitted via a form post and it includes a form field of format <input type="text" name="foo" value="bar"/> , %globals_post_foo% would print "bar".
%globals_post %An array object of all the POST variables of the current page request. You can use keyword modifiers such as ^as_url_string to convert the returned array data into a URL string value.

Current Date and Time

ReplacementInformation Shown
%globals_date%Display the current server date and time, for example, 6th Feb 2009 5:00 pm. This global keyword replacement can be suffixed with a PHP date format (ref: PHP: Date Manual) for greater control of the date and time that is displayed. For example, if you use the global keyword replacements %globals_date_M% %globals_date_Y%,  it will show "Oct  2016".
%globals_date_relative_<relative_date>%

Print a date relative to the current date and time where <relative_date> is the relative date value to return, for example, next Monday or this Friday. For a full list of relative formats visit http://php.net/manual/en/datetime.formats.relative.php.

Like the %globals_date% keyword replacement, you can append a PHP date suffix to the end of these keywords to specify the date format to display, for example, %globals_date_relative_this_friday_d-m-Y%.

Note that this keyword accepts 3 arguments separated by an underscore '_':
1 - Relative date type e.g. this, next, previous
2 - Occurrence type e.g. day, week, month
3 - Date format Y-m-d, Y/m/d (optional)

That means that only some relative PHP date keywords are supported. For example, %globals_date_relative_tomorrow% is not supported as it only passes a single argument to the keyword. Instead, you would need to use %globals_date_relative_next_day%.

Another method to use relative dates is to use the ^date_format keyword modifier to get the relative dates using PHP relative format strings:

%globals_date% => 28th Feb 2017 2:35pm
%globals_get_datestr^with_get:datestr=next friday^date_format:Y-m-d% => 2017-03-03
%globals_get_datestr^with_get:datestr=yesterday^date_format:jS M Y% => 27th Feb 2017

Current Context

ReplacementInformation Shown
%globals_context%The name of the current context the user is viewing. For more information on contexts, refer to the Contexts manual.        

Current Protocol

ReplacementInformation Shown
%globals_protocol%The communications protocol of the current URL the page was requested on, either http or https.

Random Number Generation

ReplacementInformation Shown
%globals_random%A randomly generated number. This global keyword replacement can be configured to generate a number within a set range of integers by using the format %globals_random_<MIN>_<MAX>%. For example, the global keyword replacement %globals_random_1_6%, where 1 is the minimum number and 6 is the maximum, will generate a number within that 1 to 6 range
ReplacementInformation Shown
%globals_cookie_<variable> %A cookie variable where <variable> is the name of the cookie you want to display the value of. This global keyword replacement can be used in conjunction with Triggers. For example, in the Set Cookie Trigger action, you can set the cookie name and value and then access it via this global keyword replacement. For more information about Triggers, refer to the Triggers manual.

Asset Map Icons

ReplacementInformation Shown
%globals_icon_<type_code> %The <img> tag of an asset icon where <type_code> is the asset type code of the icon you want to display. For example, %globals_icon_page_standard% will display the Asset Map icon of the Standard Page asset type.

Referrers

ReplacementInformation Shown
%globals_site_referrer%The URL of the website that the user was referred from when arriving on the Squiz Matrix site if one exists. The keyword value will remain as the first site referrer per session.
%globals_page_referrer%The URL of the web page that the user was referred from if one exists.

Visited Pages

ReplacementInformation Shown
%globals_visited_urls%An array of the URLs that have been visited by a user in the current session.
%globals_visited_assets%An array of asset IDs that have been visited by a user in the current session.

The maximum number of URLs and assets available in these keywords is by default 10. This setting can be changed in the Visited Pages Maximum Entries field on the System Configuration screen.

Entry Asset

ReplacementInformation Shown
%globals_entry_asset%The asset ID that was first accessed in the user's current session. So, for example, if the user first accessed the site through the site's Home page, which has an asset ID of #40, this global keyword replacement will display a value of 40.

SAML User Attributes

The following global keyword replacements are available to provide access to a SAML user's attributes after being authenticated by a SAML Account Manager.

For more information, refer to the SAML manual.

ReplacementInformation Shown
%globals_session_saml_attributes%A JSON string representation of all attributes of the logged-in SAML user.  You can print specific attributes using the following keyword format:
%globals_session_saml_attributes_<attribute>_0%
where <attribute> is the attribute information to print. The index can be set to specify the values to print in the array. In the above example, only the first value in the array will be specified.

Please note that a SAML user's attributes are only stored temporarily for a session. As such, these keywords are only available for the session. Permanent storage can be made available using triggers to access attributes and store them in the metadata.

Personas

Persona keywords are used to evaluate if a Persona is active or not. Persona assets are used to store custom keyword matching logic in which either evaluate the Persona as true (active) or false (not active).

For more information, refer to the Persona manual.

ReplacementInformation Shown
%globals_personas_active%Returns an asset ID array of all active Personas (server-side only) that were used when generating the page. You can use the ^in_array keyword modifier to check if a specific Persona is active or not.
%globals_persona_active:<asset id>%<asset id> is the asset ID of the Persona asset to evaluate. Will print 1 if the Persona is evaluated as true (active), or  0 if it's evaluated as false (inactive).

A suitable place to use this is in conditional keyword blocks to print conditional content based on if the Persona is active or not, for example:
%begin_globals_persona_active:1234%
  //Print content for this persona
%else_globals%
  //Print default content
%end_globals%
Please note that the keyword will only evaluate for the Server Side conditions of the Persona.

Git File Bridge

ReplacementInformation Shown
%globals_asset_url_with_hash:
<git_bridge_asset_id>:<file_path>%
Prints the full URL of a file under a Git File Bridge asset together with the latest commit hash of that file as a URL query string. For example:
%globals_asset_url_with_hash:1234:css/styles.css%
Will print something like:
https://matrix.squiz.net/__data/assets/git_bridge/0001/1234/css/styles.css?h=e6543c4