Skip to content

Instantly share code, notes, and snippets.

@sbonardt
Last active June 1, 2016 07:49
Show Gist options
  • Save sbonardt/4a34be01e15d5ba50322185259fc2f89 to your computer and use it in GitHub Desktop.
Save sbonardt/4a34be01e15d5ba50322185259fc2f89 to your computer and use it in GitHub Desktop.
Drupal: theming a field in a field collection
<?php
/*
* Template naming convention:
*
* field colelction field -> field_collection_field_name
* field example -> field_name
*
* field-collection-item--field-collection-field-name.tpl.php
* field--field__name--field_collection_field_name.tpl.php
*
* So, theming a field in a field collection is: field--field_name--field_collection_name.tpl.php
*
* if theming a field-collection use tpl below, if theming a field IN a field-collection use field.tpl as basis!
*
*/
?>
<?php
/**
* @file
* Default theme implementation for field collection items.
*
* Available variables:
* - $content: An array of comment items. Use render($content) to print them all, or
* print a subset such as render($content['field_example']). Use
* hide($content['field_example']) to temporarily suppress the printing of a
* given element.
* - $title: The (sanitized) field collection item label.
* - $url: Direct url of the current entity if specified.
* - $page: Flag for the full page state.
* - $classes: String of classes that can be used to style contextually through
* CSS. It can be manipulated through the variable $classes_array from
* preprocess functions. By default the following classes are available, where
* the parts enclosed by {} are replaced by the appropriate values:
* - entity-field-collection-item
* - field-collection-item-{field_name}
*
* Other variables:
* - $classes_array: Array of html class attribute values. It is flattened
* into a string within the variable $classes.
*
* @see template_preprocess()
* @see template_preprocess_entity()
* @see template_process()
*/
?>
<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<div class="content"<?php print $content_attributes; ?>>
<?php
print render($content);
?>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment