Created
June 5, 2013 08:03
-
-
Save opi/5712322 to your computer and use it in GitHub Desktop.
Reduce div soup in drupal theme. (like fences or field_wrappers modules)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file field.tpl.php | |
* See http://api.drupal.org/api/drupal/modules!field!theme!field.tpl.php/7 | |
* | |
* Theme suggestions: | |
* - field.tpl.php | |
* - field--TYPE.tpl.php | |
* - field--NAME.tpl.php | |
* - field--CONTENT_TYPE.tpl.php | |
* - field--NAME--CONTENT_TYPE.tpl.php | |
* | |
* See http://drupal.org/node/1089656#field-suggestion | |
*/ | |
?> | |
<?php if (!$label_hidden): ?> | |
<div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>: </div> | |
<?php endif; ?> | |
<?php foreach ($items as $delta => $item): ?> | |
<?php print render($item); ?> | |
<?php endforeach; ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file field.tpl.php | |
* See http://api.drupal.org/api/drupal/modules!field!theme!field.tpl.php/7 | |
* | |
* Theme suggestions: | |
* - field.tpl.php | |
* - field--TYPE.tpl.php | |
* - field--NAME.tpl.php | |
* - field--CONTENT_TYPE.tpl.php | |
* - field--NAME--CONTENT_TYPE.tpl.php | |
* | |
* See http://drupal.org/node/1089656#field-suggestion | |
*/ | |
?> | |
<div class="<?php print $classes; ?>"<?php print $attributes; ?>> | |
<?php if (!$label_hidden): ?> | |
<div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>: </div> | |
<?php endif; ?> | |
<?php foreach ($items as $delta => $item): ?> | |
<?php print render($item); ?> | |
<?php endforeach; ?> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements template_preprocess_field(). | |
*/ | |
function mytheme_preprocess_field(&$vars) { | |
$element = $vars['element']; | |
// Custom theme_hook_suggestions (no_markup & wrapper_only) | |
$wrapper_only_fields = array( | |
'field_block', | |
'body', | |
'field_description', | |
); | |
if (in_array($element['#field_name'], $wrapper_only_fields)) { | |
$vars['theme_hook_suggestions'][] = 'field__wrapper_only'; | |
} | |
$no_markup_fields = array( | |
'field_subtitle', | |
'field_link', | |
); | |
if (in_array($element['#field_name'], $no_markup_fields)) { | |
$vars['theme_hook_suggestions'][] = 'no_markup'; | |
} | |
} // mytheme_preprocess_field | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment