Skip to content

Instantly share code, notes, and snippets.

@joetower
Created August 5, 2013 16:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joetower/6157095 to your computer and use it in GitHub Desktop.
Save joetower/6157095 to your computer and use it in GitHub Desktop.
Drupal Bean Block Template Example
<?php
/**
* @file
* Default theme implementation for entities.
*
* 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) entity 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-{ENTITY_TYPE}
* - {ENTITY_TYPE}-{BUNDLE}
*
* 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()
*/
?>
<?php
/**
* @file
* Default theme implementation for entities.
*
* 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) entity 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-{ENTITY_TYPE}
* - {ENTITY_TYPE}-{BUNDLE}
*
* 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()
*/
?>
<?php
if(isset($content['field_box_background_image'][0]['#item']['uri'])) {
$image_file = $content['field_box_background_image'][0]['#item']['uri'];
}
if(isset($content['field_box_background_image'][0]['#item']['alt'])) {
$image_alt = $content['field_box_background_image'][0]['#item']['alt'];
}
if(isset($content['field_box_background_image'][0]['#item']['title'])) {
$image_title = $content['field_box_background_image'][0]['#item']['title'];
}
if(isset($content['field_box_background_image'][0]['#image_style'])) {
$image_style = $content['field_box_background_image'][0]['#image_style'];
}
if(isset($content['field_box_link']['#items'][0]['url'])) {
$link_path = $content['field_box_link']['#items'][0]['url'];
}
if(isset($content['field_box_headline_one'][0]['#markup'])) {
$headline_one = $content['field_box_headline_one'][0]['#markup'];
}
if(isset($content['field_box_headline_two'][0]['#markup'])) {
$headline_two = $content['field_box_headline_two'][0]['#markup'];
}
if(isset($content['field_box_sidebar_content'][0]['#markup'])) {
$callout_text = $content['field_box_sidebar_content'][0]['#markup'];
}
?>
<div class="<?php echo $classes; ?> sixteen columns alpha omega fluid"<?php echo $attributes; ?>>
<!--/callout with text - combine the headline field(s) and link field-->
<?php if(isset($headline_one) || isset($headline_two) || isset($link_path)):?>
<div class="sidebar-box-content">
<div class="text-overlay">
<h2 class="headlines">
<a href="<?php if(isset($link_path)) { echo $link_path; } ?>">
<?php if(isset($headline_one)) { echo $headline_one; } ?>
<span class="upper"><?php if(isset($headline_two)) { echo $headline_two; } ?></span>
</a>
</h2>
</div><!--.text-overlay-->
<?php endif; ?>
<!--/callout with image - combine the image field with the link field-->
<?php if(isset($image_file)):?>
<div class="sidebar-box-text-over-image">
<?php if(isset($link_path)):?><a href="<?php if(isset($link_path)){ echo $link_path;} ?>" class="image-link">
<img alt="<?php if(isset($image_alt)){ echo $image_alt;} ?>" title="<?php if(isset($image_title)) { echo $image_title;} ?>" src="<?php if(isset($image_style)) { echo image_style_url($image_style, $image_file);} ?>">
</a><?php endif; ?>
</div><!--/.callout-image-->
</div><!--/homepage-box-text-over-image-->
<?php endif; ?>
</div><!--/.div-classes-->
@BillCosbySr
Copy link

This is a great example, and incredibly helpful, thanks!

@AkilaAnuranga
Copy link

How can i get value if i have a field collection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment