Sitecmd Functions

Sitecmd includes a number of helper functions to make certain tasks faster and easier.

sitecmd::set($key, $value)

Set a Sitecmd attribute. Can also be used within your own website provided you don't conflict with any of the built-in attributes.

sitecmd::get($key, $default = null)

Get a Sitecmd attribute. Can also be used to get your own attribute values.

Passing an optional $default value will return itself if no value exists for $key.

sitecmd::add($key, $value)

Add a value to an existing attribute. This converts the attribute to an array if it's not already.

sitecmd::addEvent($event, $callback, $priority = 0)

Hook one of your functions to a Sitecmd event. Event names can be found on the Events page.

Your $callback should be located within site/_media/events.php, or a file that is included from there.

You can set an optional $priority with lower numbers taking higher priority.

sitecmd::runEvent($event, $args)

Run a given $event, passing $args as referenced variables.

Your own callback functions should modify the referenced variables rather than return or echo data.

sitecmd::path($attribute = null)

Returns an absolute path to the given $attribute, either a path in the paths attribute group, or a physical file or directory.

Useful for generating paths to various areas of Sitecmd or your own website (such as PHP include files).

sitecmd::url($path = null)

Returns an absolute URL to a location within your Sitecmd website.

Specify $path relative to your root directory and it will prepend the correct URL to the request.

sitecmd::link($url = null, $text = null, $params)

Returns a generated HTML link element (<a href="$url" $params>$text</a>).

If $text isn't specified, $url will be used for the element value.

You can pass an array of $params to pass additional attributes to the element, such as array('onclick' => "alert('clicked!')") and so on.

You can also pass an email address as the first argument and have it encoded with its ASCII equivalent. Note that you need to include the mailto: prefix to do this. ASCII encoding of email addresses can be disabled by passing array('no-encode') as the third argument.

sitecmd::getPage($comparison = null)

Returns the page name (without extension) based on the URL request.

If $comparison is set to a page name, it will return true/false based on the evaluation.

sitecmd::getURLSegments()

Returns an array of the URL components (the URL split on each forward-slash).