Last active
December 24, 2015 21:29
-
-
Save bbmatt/6865302 to your computer and use it in GitHub Desktop.
Drupal - get the path of an image without resorting to modules / Custom views-view--fields template
This file contains 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
Views template API docs: | |
https://api.drupal.org/api/views/theme!theme.inc/group/views_templates/7 | |
Function file_create_url: | |
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_create_url/7 | |
Function field_get_items: | |
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_get_items/7 |
This file contains 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 | |
// Get our node id | |
$node = node_load($row->nid); | |
// Grab an array of field items for field_image | |
$featuredImage = field_get_items('node', $node, 'field_image'); | |
// Create a url from our uri | |
$featuredImage = file_create_url($featuredImage[0]['uri']); | |
?> | |
<div> | |
<div style="background-image: url('<?php print $featuredImage; ?>');"> | |
<header> | |
<h1><?php print $fields['title']->content; ?></h1> | |
<h2><?php print $fields['field_subtitle']->content; ?></h2> | |
</header> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment