Drupal 7 Get image field path

后端 未结 5 1594
悲哀的现实
悲哀的现实 2021-01-30 18:06

I would like to get the image path of a field. I\'m in a node and I need the Url of image in order to put it as a background-image in inline css. I can\'t find the solution. Can

5条回答
  •  天涯浪人
    2021-01-30 18:48

    I am afraid, none of the solutions above are correct. They don't follow Drupal standards.

    // field_video_image is the name of the image field
    
    // using field_get_items() you can get the field values (respecting multilingual setup)
    $field_video_image = field_get_items('node', $node, 'field_video_image');
    
    // after you have the values, you can get the image URL (you can use foreach here)
    $image_url = file_create_url($field_video_image[0]['uri']);
    

    More details here: http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way

提交回复
热议问题