Rewrite results 并引用此字段为
I have a multi-value field. When I output this field in a view I use
Rewrite results and reference this field as
[field_product_image]. This outputs all the images of the field.
How could I output only certain element of this array, e.g. second image using rewrite results (this is essential)? Neither of these works:
For that you need to check the Group multiple values and then set to show 1 values and set starting from 1. see the below screenshot for clarification
if you check the rewrite output of this filed you can see the token for that filed, for your case it would probably
So if you want to retrieve the image separately from the array, you have to do the above steps for each image, for example if you want the 3rd image, then you have to set starting from 2 and its tokes is
[field_product_image_2], if you want 4th image, then you have to set starting from 3 and its token is
Below screenshots will help you to understand easily.
I added each filed separately to retrieve each image
and its tokens and above method is for Drupal 6, you can do it in the same way for D7.
I would suggest to create a template specific for this view field, so you can access all your variables with PHP, which is way more convenient to do such things.
So if your field id is "field_product_image", then you should find and download views-view-field.tpl.php, rename it "views-view-field--field-product-image.tpl.php", put your code inside and upload it to your theme/template folder.
You can see in your view, under "Advanced" > "Theme" what is the name to override default views field template and if the overriding template is used.
It is assumed in this question that defining which values to output and how to output them would have to happen in the same place, Rewrite results. However, there is nice support for separating these in (D7) Views Configure Field dialog: Multiple field settings for "what" and Rewrite results for "how".
So for D7 use "Multiple field settings". For example "Display 1 starting from 1" outputs the second image. Now you can access your image in "Rewrite results" simply using [field_product_image].
In D6 these settings are in the same dialog, but they work the same way, I believe.