Skip to content

Instantly share code, notes, and snippets.

@donbrae
Last active May 16, 2023 12:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donbrae/2f6d74a2431c45a885f88eb1da493be5 to your computer and use it in GitHub Desktop.
Save donbrae/2f6d74a2431c45a885f88eb1da493be5 to your computer and use it in GitHub Desktop.
This cheat sheet documents various shortcuts, tips and tricks, and productivity boosters. Tested on Matrix v5.4.0.1 on macOS.

Keyboard shortcuts

  • Ctrl + + S to Save
  • Ctrl + + A to Acquire Locks
  • Ctrl + + R to Release Locks
  • Ctrl + + N to invoke the Next button
  • Delete to move selected assets in the Asset Map to the Trash

Releasing all your locks

The quickest way to release all your locks while in admin mode is via the My Account tab at the top of the Asset Map. Just click the Release Locks button.

Accessing screens

In the admin interface, the quickest way I've found to access another screen belonging to the current asset is to click anywhere on the div with class .sq-backend-main-header-top, press the Tab key once to focus on the #screen_menu dropdown, then type the name of the desired screen (or use the arrow keys).

For example, if you're viewing the Details screen of a particular asset and want to access the Settings screen, click on the div at the top of the main panel (the one with the info icon, and asset ID and name), tab once and start typing "Settings". Alternatively, use the up and down arrows, then Enter or Space to select.

Keyword replacements

The Matrix Manuals site has complete documentation on common and global keywords.

Custom Forms

Here are a couple of keyword replacements I've found useful on a few occasions when working with Custom Forms:

  • Get value of metadata field of specific asset, e.g. get the value of the metadata field foo on the Form Submission asset with ID form_submission_id: %form_submission_id^as_asset:asset_metadata_foo%. This example could be used in the Email Options screen of a Custom Form, for example
  • When listing Form Submission assets via an Asset Listing, access the responses thus: %question_answer_123456_q7%. In a Custom Form bodycopy, or in the Email Options screen of the Custom Form's Form Contents asset, access the same response thus: %response_123456_q7%

If a Trigger is used as part of your form — for example, a Trigger which runs when the form is submitted and the Form Submission asset is created — you can access user responses in the relevant POST data variable. In the Trigger Details screen, set a POST Variable Name as Dynamic Parameter in the following format: q123456:q11. "123456" is the Form Section; "q11" is the Form Question. (The ID of the actual Matrix asset has the following format: 123456:q11.) I've used this approach to, for example, update the title attribute of user-uploaded PDF files with a friendly name (specified in a form field) which is then displayed on the front end via an Asset Listing.

Keyword modifiers

See the Matrix Manuals site for full keyword modifiers documentation.

There's particularly cool stuff here.

  • Conditionals, e.g. %response_123456_q2^eq:Male:someemail@test.com:anotheremail@test.com%. This checks whether question 123456_q2 (related to a Form Submission asset) has the response of "Male"; if so, it prints email address someemail@test.com; else it prints anotheremail@test.com
  • There is an "is not empty" conditional, which can be used to check for a query string parameter: %globals_get_derp^notempty:There's a "derp" parameter in the query string%
  • You can also, for example, check an asset's parent: %asset_parent^as_asset:asset_type^eq:Comment:The parent asset is of type "Comment"
  • The following converts a string metadata field to an array (splitting at the semicolon) and gets the first item: %asset_metadata_foo^explode:;^index:0%
  • To check whether the last item in an array (again based on a string delimited by semicolons) is empty or has a value: %asset_metadata_foo^explode:;^array_reverse^index:0^eq::EMPTY:HAS VALUE%
  • Get the first word from a string (if the first words are hypenated, it'll return both hyphenated words): %<keyword>^replace:(\s).*$:%
  • Get the last word from a string (if the last words are hypenated, it'll return both hyphenated words): %<keyword>^replace:.*(\s):%
  • You can format %event_datetime_summary% conform to your site’s style guide. %event_datetime_summary^replace:-: – ^replace:th:^replace:rd:^replace:st:^replace:nd:^replace:\:00:^replace:\::.% will convert 30th May 2020 9:00am-5:30pm, for example, to 30 May 2020 9am – 5.30pm; or 30th May 2020 9:00am - 31st May 2020 5:30pm to 30 May 2020 9am – 31 May 2020 5.30pm.

Getting attribute etc. for specific asset ID

Examples:

  • %globals_asset_thumbnail:123456% (Returns thumbnail of asset 123456 as <img> element)
  • %globals_asset_thumbnail_url:123456% (Returns URL of asset 123456's thumbnail image)
  • %globals_asset_thumbnail_alt:123456% (Returns alt text of asset 123456's thumbnail image)
  • %globals_asset_attribute_height:123456% (Returns height of image asset 123456)
  • %globals_asset_attribute_alt:123456% (Returns value of alt text attribute of image asset 123456)

Don’t have the asset ID? Use the ^as_asset keyword modifier:

  • %globals_asset_metadata_foo^as_asset:asset_url% (Where foo is a Related Asset Field pointing to an asset, this example returns the asset’s URL)
  • ^as_asset can be chained, e.g.: %nested_get_foo^as_asset:asset_parent^as_asset:asset_name% (In a nested asset, use the value of GET variable foo [an asset ID] to get the ID of foo’s parent asset, then use this ID to get the name of foo’s parent asset. See the Nest Content chapter in the manuals for info on passing variables to nested assets)

Nested keywords

The below example uses a nested keyword {globals_site_name} to print the name of the current website if the current site name is not "lorem ipsum website".

The ^trim and ^lowercase modifiers are also employed so that the conditional is not affected by leading or trailing space in the site name, nor which case it's in.

%globals_site_name^trim^lowercase^neq:lorem ipsum website:{globals_site_name}%

Below is a more complex example. This can be used in an Asset Listing (in the relevant Type Format bodycopy asset) to print Single Calendar Events occuring in the past:

%event_start_date^lt_date:{globals_date_Y-m-d}:
<div class="event">
    <p>{event_start_datetime_d} {event_start_datetime_F} {event_start_datetime_Y}</p>
    <h3>{asset_name_linked}</h3>
    <p>{asset_attribute_description^maxwords:40^trim}{asset_attribute_description^wordcount^gt:40:...:}</p>
    <p><a href="{asset_url}">Read More</a></p>
</div>
%

Keyword observations

Some examples highlighting quirks that I’ve observed…

/* Doesn't work due to output having spaces */
%globals_get_foo^notempty:{globals_get_foo^wordcount^gt:1:GREATER THAN 1}%

/* Does work when spaces are removed from output */
%globals_get_foo^notempty:{globals_get_foo^wordcount^gt:1:GREATERTHAN1}%

/* Does work as there is no nested keyword replacement */
%globals_get_foo^wordcount^gt:1:GREATER THAN 1%

/* Doesn't work with ^explode */
%globals_get_tags^notempty:{globals_get_tags^explode:,^count^gt:1:MORETHAN1}%

/* Works because ^notempty has been removed, but we can't differentiate between one or no values */
%globals_get_tags^explode:,^count^gt:1:MORE THAN ONE:ONE OR ZERO%

Miscellaneous

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment