By yan


2014-07-08 16:00:17 8 Comments

What sounds like simple task in the first place, has taken me hours without getting a solution: All I want is to render single values of an imagefield just as in the normal node, i.e. as defined in content-field.tpl.php. This is important for me, because there I add captions from the Imagefield Extended module

I tried with content_format(), but with the "default" formatter it gives me just an icon and a link and with the "image_imagelink" formatter from the imagefield.module I get an image, but not as defined in content-field.tpl.php and in the node type's display settings:

print content_format('field_image', $vars['node']->field_image[1], 'default', $vars['node']);
print content_format('field_image', $vars['node']->field_image[1], 'image_imagelink', $vars['node'])

I have tried a couple of other things and searched for hours, but I cannot find an answer. Any ideas how I can render the image "just the normal way"?

The HTML out I want is a defined in the template something like this:

<div class="field field-type-filefield field-field-image">
  <div class="field-items">
    <div class="field-item odd">
      <a class="imagefield imagefield-lightbox2 imagefield-lightbox2-page-grid-6 imagefield-field_image imagecache imagecache-field_image imagecache-page-grid-6 imagecache-field_image-page-grid-6 lightbox-processed" rel="lightbox[field_image][Caption text]" href="http://example.com/files/imagecache/image_full/img/2014/img.jpg">
        <img width="364" height="242" title="Caption text" alt="Caption text" src="http://example.com/files/imagecache/page-grid-6/img/2014/img.jpg">
      </a>
      <div class="img-meta">
        <div class="img-title">
          <p>Caption Text</p>
        </div>
        <div class="img-source-info">
          <div class="img-source">
            <span class="img-source-label label">Source:</span> 
            <span class="img-source-content content">Source text</span>
          </div>
          <div class="img-license">
            <span class="img-license-label label">Licence:</span> 
            <span class="img-license-content content">Licence text</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

1 comments

@Alexis Wilke 2014-07-12 23:16:39

Do you have more than one image?

print content_format('field_image', $vars['node']->field_image[0], 'default', $vars['node']);
print content_format('field_image', $vars['node']->field_image[0], 'image_imagelink', $vars['node']);

Try again with [0] instead of [1]. I use those all the time and it works fine like that.

@yan 2014-07-13 13:27:06

Hi Alexis, actually I was using a loop to print all the images, the "1" was just one instance, so that doesn't solve the problem. As I said, I changed some stuff in the field's template file and those changes are not reflected when I use content_format().

@Alexis Wilke 2014-07-13 21:40:02

Ah! I have to say I try to avoid using theme() in general because of all the caching and stuff, it often does not come out exactly as you want it. But anyway, in your case, you may have a cache problem. The theme() functions save all sorts of things in the cache under the hood and if those caches exist, they ignore your other changes.

Related Questions

Sponsored Content

1 Answered Questions

Create imagefield with maximum number of values programmatically

  • 2017-01-02 18:20:34
  • Alter Ego
  • 26 View
  • 0 Score
  • 1 Answer
  • Tags:   forms media

2 Answered Questions

[SOLVED] Render module block programmatically

  • 2016-06-30 09:24:26
  • Yusef Mohamadi
  • 592 View
  • 2 Score
  • 2 Answer
  • Tags:   theming 8

2 Answered Questions

[SOLVED] How to populate nodes with imagefield programmatically?

  • 2011-07-20 06:09:38
  • Logi
  • 788 View
  • 1 Score
  • 2 Answer
  • Tags:   7 media

1 Answered Questions

[SOLVED] Create imagefield and set min width and height programmatically

  • 2016-10-02 16:05:58
  • hg96nl
  • 66 View
  • 2 Score
  • 1 Answer
  • Tags:   7 media

1 Answered Questions

[SOLVED] Render image programmatically based on field content

  • 2016-03-03 23:11:47
  • Megan McGowan
  • 559 View
  • 0 Score
  • 1 Answer
  • Tags:   theming entities 8

3 Answered Questions

[SOLVED] A General Strategy for Images with Captions in Content

  • 2013-02-26 04:50:55
  • Blue Waters
  • 2349 View
  • 4 Score
  • 3 Answer
  • Tags:   7 media nodes

0 Answered Questions

Custom Content with Image upload button drupal 7 programmatically

  • 2015-07-23 18:14:55
  • Gabriel
  • 75 View
  • 1 Score
  • 0 Answer
  • Tags:   media

2 Answered Questions

[SOLVED] Create drupal content programmatically with custom entity ( assets )

  • 2014-10-07 15:54:26
  • user3932702
  • 663 View
  • 2 Score
  • 2 Answer
  • Tags:   media

2 Answered Questions

How to set defined image weight in Drupal

  • 2014-09-27 12:47:19
  • user1981528
  • 62 View
  • 0 Score
  • 2 Answer
  • Tags:   media

2 Answered Questions

[SOLVED] How to assign ImageCache setting to an imagefield in content type

  • 2011-09-25 10:37:00
  • Immers
  • 144 View
  • 0 Score
  • 2 Answer
  • Tags:   6 media

Sponsored Content