P
P
Pavel Usov2014-09-12 15:13:05
Drupal
Pavel Usov, 2014-09-12 15:13:05

How to get image link value in Drupal view?

created a template views-view-fields--review--page.tpl.php ,
inside you can call the values ​​of the variable $fields['field_image_service']->content ,
how can you get the url value from the field for the picture, and the thumbnail and the original?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
pibiv, 2014-09-12
@pibiv

I'm not sure, but when we ask through ->content, it gives us the already rendered result. That is, all links are tags, etc. will already be there.
perhaps you need to dig somewhere deeper, for example, through the field preprocess in template php, pick out the values ​​\u200b\u200bthat you need to shove them into a variable and use them on the page with the view.

S
Silo, 2014-09-12
@Silo

Content content in this case is just text. It is possible to process it as a text variable, but it is undesirable to do this in the template file - the site will be extremely difficult to update or repair if something happens.
In the template you created, write a command to view the contents of the element:
dpm($field['field_image)service']);
(do not forget to wrap the command in php tags)
after that you reload your page in the browser. At the top, where Drupal system messages are displayed (like "you have created content", etc.), a message will appear containing the complete structure of your field object.
In the structure, in addition to the actual content, there will be a field of the url itself - this is a link to the native image.
Further, the link can be obtained by contacting the name of the url field. Something like $fields['field_image_service']->url (the exact name of the field must be found on your site)
There will be no link to the thumbnail, because this is the same native image processed by the image filter.
in template.php we write hook_preprocess_field, in it we write a handler for the field with a picture, which in fact will do the same as described in the first method, but will allow you to extract the url and save it to a separate variable, which can then be called in views-view -fields--review--page.tpl.php
This method also allows you to edit the content of the content field for this field. In particular, you can add alternative text to the picture, a tooltip, meta tags, or draw your own styles.
In any case, your image field is an object where the content is just one of the object's fields. You just need to extract the value of another field of the same object.

U
UksusoFF, 2014-09-12
@UksusoFF

Through overwriting the value, you can display the link, and you can put Views PHP and play around with the value there.

I
Igor Che, 2016-12-08
@chewarer

Here is a module for just that: Image formatter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question