L
L
lacrim2015-11-26 18:07:27
Drupal
lacrim, 2015-11-26 18:07:27

How to themize an image field in Drupal 7?

Hello colleagues, tell me who came across how to themize the image field in the seventh (7.41) Drupal?
I know this is done by creating a file like field--FIELD_MYIMAGE.tpl.php
But here's the catch, all I've been able to dig up in the field module files is primitive type inference:

<?php foreach ($items as $delta => $item): ?>
   <?php print render($item); ?>
 <?php endforeach; ?>

And I need a detailed one, where the tag itself is set. Why all this? - I want to put an image on the background Instead of the standard one:<img...


<div class="field field-name-field-image field-type-image field-label-hidden">
 <div class="field-items">
  <div class="field-item even" rel="og:image rdfs:seeAlso" resource="my.jpg">
   <img typeof="foaf:Image" src="my.jpg">
  </div>
 </div>
</div>

Do like this:
<div class="field field-name-field-image field-type-image field-label-hidden">
 <div class="field-items">
  <div class="field-item style="background-image: url('my.jpg');">
  
  </div>
 </div>
</div>

I would be grateful for any kicks in the right direction =)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
andead, 2015-11-26
@andead

print_r($items);

T
Tlito, 2015-11-27
@tlito

detailed where the img tag itself is set,
you need above the line `<?php print render($item); ?>`
view this variable. enable the Devel module and use the variable lookup function
`dpm($item);
and having learned that instead of `render...` you can do any code like
` $item%5B'und'%5D%5B0%5D`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question