Have you tried using theme_field functions and/or template_preprocess_node() in template.php? For example:
/**
* Implements theme_field__field_name().
*/
function myThemeName_field__field_cta_button($vars) {
// Get the current value of cta_text, if it exists.
if ($field_cta_text = field_get_items('node', $vars['element']['#object'], 'field_cta_text')) {
$cta_text = $field_cta_text[0]['value'];
}
// If cta_text isn't set for this node, set a default. You may not need this.
else {
$cta_text = '';
}
// Print the button differently depending on whether or not cta_text is available.
// This could mean you actually return different markup here, or you could alter the variables available to you in the tpl (I would just return the markup here if it's simpler).
switch ($cta_text) {
case 'foo':
return "<button class='foo'>{$vars['element']['#items'][0]['value']}</button>";
break;
case 'bar':
default:
return "<button class='bar'>{$vars['element']['#items'][0]['value']}</button>";
break;
}
}
OR in template_preprocess_node()
:
myThemeName_preprocess_node(&$vars) {
if ($vars['node']->type == 'your_content_type') {
$field_cta_text = field_get_items('node', $vars['node'], 'field_cta_text');
if ($field_cta_text[0]['value'] == 'foo') {
$vars['node']->field_cta_button['custom_key'] = 'custom value'; // This would be available to you in the theme_field__field_cta_button() function as well as in the field .tpl file.
}
}
}
You can still do it in the .tpl as is noted in the other answer by accessing $element['#object'], but I would recommend doing it in the theme_field() function or in the preprocess function. From the field.module documentation:
* Theme developers who prefer to customize templates instead of overriding
* functions may copy the "field.tpl.php" from the "modules/field/theme" folder
* of the Drupal installation to somewhere within the theme's folder and
* customize it, just like customizing other Drupal templates such as
* page.tpl.php or node.tpl.php. However, it takes longer for the server to
* process templates than to call a function, so for websites with many fields
* displayed on a page, this can result in a noticeable slowdown of the website.
* For these websites, developers are discouraged from placing a field.tpl.php
* file into the theme's folder, but may customize templates for specific
* fields.