Template Tags
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Component created
Component changed
Component body
This module lets you define custom tags which you can use anywhere and in any of your templates. You can attach your own callbacks to perform on loading.
The default implementation is linking a node to a custom tag. Handy for when you have several overview pages and want to refer to these in your template.
E.g.
<a href="<?php print $template_tags['photo-overview']['default']['node_link']; ?>"> some link </a>
Or you can do more fancy stuff (such as rendering a part of a node) with your own custom callbacks.
This module allows setting a custom node for each language installed within Drupal.
When defined, this module also uses the _preprocess hook to
push them towards the variable $template_tags where you can retrieve
their value or the callback results. This variable is available anywhere in
your template.
Definition example:
Within your module define the hook_define_custom_token and return an
array something like this:
$item = array();
$item['example_token'] = array(
'name' => 'Example custom token',
'token' => 'example_token',
'token callback' => 'tools_token_example_callback',
);
Whereas:
name = The name in the administration views.
token = The machine readable name for the token
(must be using underscores)
token callback = An optional callback function for when the token
is retrieved.
In your template refer to the token like this:
$template_tags['example_token']['default']; // for the default callbacks
$template_tags['example_token']['callback']; // for the callback results
And that is it. You can attach a node to a custom token by visiting:
admin/config/template-tags
/**
* Example implementation {
*/
function template_tags_define_template_tag() {
$item = array();
$item['example_token'] = array(
'name' => 'Example custom token',
'token' => 'example_token',
'token callback' => 'template_tags_example_callback',
);
return $item;
}
/**
* The result of all of this will be like this
*
* $template_tags['example_token']
* ['callback']
* ['example'] => "callback"
* ['token'] => [Contents of the token passed to this callback]
*
*
* As each token is also processed through template_tags_tag_values upon loading it will also contain,
* if this is saved through the interface ofcourse, a key callled ['default']['node_link'] with a proper
* url to the specified node.
*
* Just imagine the possibilities :-)
*
*/
function template_tags_example_callback($token) {
return array('example' => 'callback', 'token' => $token);
}
/**
* Example implementation }
*/
