vae_register_tag()
Use the vae_register_tag()
function to register your own
VaeML tag. You define a function that will render your tag and
we will call it when needed by a page.
Usage
vae_register_tag($name, $options)
-
$name
- Name for the tag you are registering. You do not need to including the leadingv:
. For example, to create the tag<v:calendar_widget>
, you would specify a value ofcalendar_widget
here. Note that you can redefine built-in Vae tags if you so choose! -
$options
- PHP associative array containing the following components:-
handler
- PHP function that will be run to render the tag. You may optionally omit if you are defining acallback
. -
callback
- if set, this specifies that this tag will render a form and submit data back to the server. The value that goes here is the name of the PHP function that you have defined that should be run when data is posted to the server. If your handler returnstrue
or you do not specify a handler, this tag will automatically render as a<form>
tag that posts back in such a way that this callback will be invoked on receipt of thePOST
. -
html
- if your tag returns a standard HTML tag, specify that tag here and all options that are valid for that tag will be considered valid for your tag. -
params
- array of the attributes that are accepted for your tag. Or, set this tocollection
to accept all the parameters that are normally accepted by<v:collection>
. -
required
- array specifying which parameters are required.
-
Returns
Returns true
.
How to define your functions
Handler Functions
Handler functions are called with 5 parameters, which by convention are named as follows:
-
$a
- associative array of the attributes provided to the tag. -
$tag
- an associative array which describes the tag. Includes the following members:-
attrs
- same as$a
-
index
- unique ID of this rendering instance of this tag. If this tag is called within a collection tag, each time the tag is rendered will have a different index -
innerhtml
- HTML code inside this tag -
tags
- array of tags nested inside this tag
-
-
$context
- the current VaeQL context. Should be used in any calls tovae()
orvae_find()
that you make. -
$callback
- array that you can use to save data that will be made available to your callback function. -
$render_context
- contains information about the current VaeML rendering context. This should be passed to vae_render_tags() if you need to call that function.
Use the vae_render_tags() function to render inner tags.
The return value of this handler function will be used as the rendered contents of your tag.
Callback functions
Callback functions are called with a single parameter – $tag
. It is
the same as above, but also contains an entry called callback
that
contains the values stored in $callback
in the handler function. The
handler function is always run on callbacks, before the callback tag is
invoked.
Generally, you will call vae_redirect() in your
callbacks to direct the visitor somewhere. A common convention is to
return vae_redirect($tag['attrs']['redirect']);
at the end of your
callback. If you return any other value, it will be sent to the browser.
Sample Usage
Here are a few different sample tags.
Basic Example: TodaysDate
This will create a tag <v:todays_date>
that renders today’s date.
Example HTML file:
Basic Example: StripeRow
This will render table rows with alternating CSS classes to achieve a “striped background” effect.
Example HTML file:
Of course, you can now use <v:tr_striped>
inside <v:collection>
tags, which is where it would truly be valuable.
Intermediate Example: IfCurrentDomain
This will render code only if the current domain name matches a specified domain name. This is useful if you have multiple domain names leading into your site.
Now in your HTML files, you can use:
Server-side processing: BetterFormmail
This will create a replacement for the <v:formmail>
tag.
Now in your HTML files, you can use: