Content Commands are strings added directly into the content that are executed when the content is viewed on the website. An example is the command { % user firstname % }which displays the first name of the user.
(Note: in all cases, commands open with "{ %" and close with "% }" except there should be no space between the percent and the close-brace.)
Command Execution
When a command is executed, it loads or modifies its internal Accumulator. When the command is complete, the resulting Accumulator is returned to the page. For instance, the command { % user firstname % } first loads the accumulator with the user's first name. When the end of the command is encountered the entire command string is replaced with the contents of the accumulator.
Shortcut Command Syntax
A simple command has a command and an optional single argument. To execute a simple command, include it in the command block. If the command or its argument includes a space they must be quoted.
- { % user firstname % } - outputs the users firstname
- { % "user" "firstname" % } - also valid
- { % open "/my template.html" % } - opens the file named "my template.html" from the website root folder and outputs it
Full Command Syntax
More complex commands can include multiple arguments and/or have enumerated arguments (arguments that include both a name and a value, like color="blue" and position="top"). In this case, JSON syntax is used to encode the arguments. A command is a JSON object where the command is included either as the first argument or with the argument name "arg".
The general syntax is a single JSON object with one property. The name of the property is the command name and the value of the property is the command's argument(s)
For commands with a single argument use the following syntax.
{ % {"commandName" : "commandArgument" % }
For Commands with multiple arguments use the following.
{ % { "commandName" : { "argName1" : "argValue1", "argName2" : "argValue2" }} % }
For Example:
- { % {"user":"firstname" } % } - outputs the users firstname
- { % {"addon" : { "addon":"My Custom Addon","color":"blue" }} % } - runs an addon named "My Custom Addon" with the argument color=blue
Multiple Commands in the same Command Block
Multiple commands can be used in the sample command block "{ % % }". The first commands loads the accumulator and each subsequent command modifies it. Use JSON array syntax to hold multiple commands.
The following command first loads the users firstname, then does and find-and-replace, changing lower case "a" to lower case "b"
{ % [ { "user" : "firstname" } , {"set" : { "find":"a","replace":"b"}} ] % }
Commands
textBox
Opens a record from Copy Content. If editing is enabled, content managers get an edit icon for this copy.
{ % textbox "home page footer" % }
{ % {"textbox" : { "name":"home page footer" }} % }
openCopy
Opens a record from Copy Content without editing support.
{ % opencopy "home page footer" % }
{ % {"opencopy" : { "name":"home page footer" }} % }
openLayout
Opens a record from Layouts.
{ % openLayout "Organization List Item" % }
open
Opens a file in the website root path.
{ % open "/homeTemplate.html" % }
import
Opens a file in the website root path and includes its head elements in the current page.
{ % import "/homeTemplate.html" % }
user
Opens a field from the current user's record.
{ % user firstname % }
{ % { "user" : { "field":"firstname" }} % }
site
Opens a site property.
{ % site "Caption for My Form" % }
{ % { "site" : { "name":"Caption for My Form" }} % }
set
Performs a find and replace on the current accumulator.
{ % {"set" : { "find":"good","replace":"great" }} % }getInner
Find and returns the string in the accumulator based on a style selector in the find argument.The innerHtml is everything inside the start and end tag.
For the following html:
returns the innerHtml of all elements with the class "main-nav", in this case it returns: "this is the text in the middle"
setInner
Performs a find and replace on the current accumulator, where the find argument is a style selector and when it is found, the inner Html of that elements is replaced by the value of the replace argument. The replace argument can be another JSON command like "open" or "getInner"
{ % {"setInner" { "find":".left-nav","replace":"Left Navigation" }} % } - replaces the innerHtml of all elements with class "left-nav" with the text "Left Navigation"
{ % {"setInner" : { find":".footer-nav" , "replace": {"menu" : "Footer Menu" }}} % } - replaces the innerHtml of all elements with class "footer-nav" with the output of theMenu add-on run with the argument name="Footer Menu"
getOuter
Find and returns the string in the accumulator based on a style selector in the find argument.
{ % {"getOuter" : { "find":".main-nav" }} % } - returns the outerHtml of all elements with the class "main-nav". The outerHtml is everything inside the tag, plus the opening and closing tag.
setOuter
Performs a find and replace on the current accumulator, where the find argument is a style selector and when it is found, the outer Html of that elements is replaced by the value of the replace argument. The replace argument can be another JSON command like "open" or "getOuter". The outerHtml is everything inside the tag, plus the opening and closing tag.
{ % {"setInner" { "find":".left-nav","replace":"Left Navigation" }} % } - replaces the innerHtml of all elements with class "left-nav" with the text "Left Navigation"
{ % {"setInner" : { find":".footer-nav" , "replace": {"menu" : "Footer Menu" }}} % } - replaces the innerHtml of all elements with class "footer-nav" with the output of theMenu add-on run with the argument name="Footer Menu"
addon
Execute an addon and replaces the accumulator with the results. The command is "addon" and it has two arguments, the addon name and the addon's arguments.
{ % {"My Custom Addon" : { "color":"blue" }} % } - runs an addon named "My Custom Addon" with the argument color=blue
An example with multiple arguments. This creates a page extension named Lydia that changes for each section.
{ % { "page extension" : { "extensionname":"Lydia", "extensiontype" : "section"}}%}
All Others
Attempt to locate an addon with the name matching the command