[ Previous: G. How the Parser Works ]
In versions 1.0 through 1.3 of NBBC, the tag parameters provided to the callback function were fairly simple and straightforward. There were the parameters provided by the user, and these three parameters were provided by NBBC itself:
However, in v1.4 and later of NBBC, the tag parameters have been expanded to include the following additional parameters:
Array( Array("key" => "font", "value" => "Arial"), Array("key" => "size", "value" => "5") )While this may appear to be identical to the array that contains it, it's not. First, the 0th array element is always set to the tag's default value (even if there is no default value), and second, if redundant parameters are provided, this will list them separately. For example:
[includes file="Larry" file="George" file="Bill"] => Array( Array("key" => "includes", "value" => ""), Array("key" => "file", "value" => "Larry"), Array("key" => "file", "value" => "George"), Array("key" => "file", "value" => "Bill") )
In addition, in v1.4, the rule was established that no user-provided parameter may have a name that starts with an underscore (_); names that start with underscores are reserved for use by NBBC itself.
Some of these values are debatably useful; for example, the _end parameter is primarily used by NBBC to ensure proper tag parsing and doesn't help a callback rule much. But others, such as the new _params parameter, provide significant power to callback rules that they never had before.
In particular, the _tag and _endtag parameters are now provided so that callbacks can do late validation of their data. For example, consider a callback for the tag [fruit]. This callback wants to allow [fruit]apple[/fruit] and [fruit]orange[/fruit] but not [fruit]green[/fruit]. The callback cannot use the validation stage of rule processing to answer this because it doesn't know what its contents will be until it has already said "yes". But with the _tag and _endtag parameters, the [fruit] tag can now "fake" correct behavior:
Notice how this callback, if given an invalid type of fruit, simply returns the original tag and its contents, unchanged. This pattern is used in several places in the Standard BBCode Library in NBBC v1.4, and can be very useful in your own rules as rell.
[ Previous: G. How the Parser Works ]