Using a qtag's target and attributes

The structure of a qtag Function

A qtag function, has three parameters: 

$env - The Environment (passed by default, can't be changed)

$target - The qTag's target (a string)

$attributes - An array of other attributes of the qtag 

Using a qtag's target

For a simple example of using target, let's examine the [STRING] qtag.

function qtag_STRING($env, $target, &$attributes) {
  return $target;
}

Using:

[STRING:Hello World!]

anywhere in your code (index.html, templates, node body, etc.) will trigger qtag_STRING passing the target 'Hello World!

As you can see from the above function's body, this will result in a printed version of the target string.

In example: Hello World!

Using a qtag's Attributes

For a simple example of using attributes, let's examine the [RANDOM] qtag.

function qtag_RANDOM($env, $target, &$attributes) {
  $min = isset($attributes['min']) ? $attributes['min'] : 0;
  $max = isset($attributes['max']) ? $attributes['max'] : 1000000;
  return rand($min, $max);
}

Using:

[RANDOM|min=10|max=20]

anywhere in your code (index.html, templates, node body, etc.) it will then trigger qtag_RANDOM passing the attributes 'min' = 10 and 'max' = 20. 

As you can see from the above function's body, this will result in a random number between min (10) and max (20).

In example: 13

Note that in this example we did not specify any target, that's implied null and not used for this qtag.

So what a full qtag looks like?

Combining target and attributes, a typical qtag could look like:

[LINK|link_title=Click to go to the wikipedia site|protocol=https|title=Go to wikipedia:www.wikipedia.org]

This will result in the link below:

Go to wikipedia