I have a node content type with multiple images and I would like to get the first image only. In order to get the first image I need to use - instead of _.

For example:
[node:my-image:0:image-style-name]

I tried to add the following to imagecache_token_token_info_alter() but still no luck:

$token_type = token_get_entity_mapping('entity', $entity_type);
if (!empty($data['tokens'][$token_type][$field['field_name']])) {
  $data['tokens'][$token_type][$field['field_name']]['type'] = 'image-field';
}

// Also check for tokens that are using dashes.
$dash_field_name = str_replace('_', '-', $field['field_name']);
if (!empty($data['tokens'][$token_type][$field['field_name']])) {
  $data['tokens'][$token_type][$field['field_name']]['type'] = 'image-field';
}

If anyone has any suggestions I can write the patch.

CommentFileSizeAuthor
#2 image_token.png131.47 KBtannguyenhn

Comments

albertski created an issue. See original summary.

tannguyenhn’s picture

StatusFileSize
new131.47 KB

Albertski
I can see module version 7.x-1.0-rc2 and dev already support do this. If you only want get first image please enter token [node:field_name_image:image_style:first] without custom anycode :D

tannguyenhn’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.