This project is not covered by Drupal’s security advisory policy.
Token Field allows you to define read-only CCK Fields which generate their output using Tokens.
Example
For example, you may have 3 CCK Fields:
- field_currency - (Text, Select Box)
- field_minimum - (Numeric, Textfield)
- field_maximum - (Numeric, Textfield)
You may want to output this as a single field, eg: $100-200
. Currently you could do this using a custom module, a theme level template file or the awesomely powerful Computed Field.
Wouldn't it be nice to just define a "template field" without needing to know any PHP?
Enter Token Field.
Using this module you just add a new field to the content type and define the "template" code (which also uses Input Filters). You could setup:
<span class="currency">[field_currency-raw]</span><span class="min">[field_min-raw]</span><span class="max">[field_max-raw]</span>
You have access to the CCK Field for the current node, all other Node level tokens and all Global Tokens.
You can essentially use this to create a Compound CCK Field using Tokens.
Conditional Tokens
A new feature in version 1.3 is conditional tokens using PHP code. You can enable PHP Parsing on the template which would allow you to do something like this:
$items = array();
if (!empty($node->field_foo[0]['value'])) {
$items[] = '<span>[field_foo-formatted]</span>';
}
if (!empty($node->field_bar[0]['value'])) {
$items[] = '<span>[field_bar-formatted]</span>';
}
if (!empty($node->field_baz[0]['value'])) {
$items[] = '<span>[field_baz-formatted]</span>';
}
print implode (' | ', $items);
This would allow you to have between zero and all three tokens present in the field, separated by a pipe. If you did this with a non-php field, you could end up with three pipe symbols appearing if all three tokens were empty.
The PHP code in the template has read-only access to the current $node
, $field
, $items
, $delta
and $teaser
/$page
flags.
Drupal 7
There is a working version for Drupal 7 as a development release, however until #691078: Field tokens is solved, there are no field-level tokens available which kind of restricts the point of the module. The module seems to function ok with normal tokens though. Once the Field Tokens issue is resolved, I will release a supported version of this module for D7.
Sponsorship
- This project is sponsored by Haymarket Media Group and iO1. We provide specialist consulting services in Enterprise Drupal, Views & Panels, Visit us at www.io1.biz or Contact us.
Project information
- Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed. - Maintenance fixes only
Considered feature-complete by its maintainers. - Module categories: Content Editing Experience
- 651 sites report using this module
- Created by nicholasThompson on , updated
- This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.