2011-10-07 39 views
20

मैं एक फ़ील्ड का छवि पथ प्राप्त करना चाहता हूं। मैं एक नोड में हूं और मुझे इनलाइन सीएसएस में पृष्ठभूमि-छवि के रूप में रखने के लिए छवि के यूआरएल की आवश्यकता है। मुझे समाधान नहीं मिल रहा है। क्या आप मेरी मदद कर सकते हैं?Drupal 7 छवि फ़ील्ड पथ प्राप्त करें

उत्तर

49

सिर्फ एक छवि का पथ प्राप्त करने के लिए यह यूआरआई है से: file_create_url (पर

file_create_url($node->field_image['und'][0]['uri']);

अधिक जानकारी) यहां पाया जा सकता: http://api.drupal.org/api/drupal/includes%21file.inc/function/file_create_url/7

इसके यूआरआई उपयोग से छवि शैली का उपयोग करके बनाई गई छवि का मार्ग प्राप्त करने के लिए:

image_style_url पर

अधिक जानकारी() यहां पाया जा सकता: http://api.drupal.org/api/drupal/modules!image!image.module/function/image_style_url/7

+0

ने मेरी जान बचाई। धन्यवाद! –

+2

यह बहुभाषी क्षेत्रों को ध्यान में रखता नहीं है। नीचे @Gergely द्वारा जवाब देखें। यहां तक ​​कि यदि आपको लगता है कि आपकी साइट को "कभी भी" अनुवादों का समर्थन करने की आवश्यकता नहीं है, तो कृपया ऐसा न करें। अधिक जानकारी के लिए, http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way –

+1

अद्भुत..it मदद –

5

मैं कुछ देर इस का उपयोग करें:

$node = node_load($nid); 
$img_url = $node->field_userimage['und'][0]['uri']; 

<img src="<?php print image_style_url($style, $img_url) ?>" /> 
+3

आप [theme_image_style()] (http://api.drupal.org/api/drupal/modules--image--image.module/function/theme_image_style/7) का उपयोग भी कर सकते हैं हार्ड- थीम फ़ंक्शन का उपयोग करके ' 'टैग – Laxman13

+3

कोडिंग को बहुत पसंद किया जाएगा:' थीम ('image_style', array ('style_name' => 'name', 'path' => $ node-> field_userimage ['und'] [ 0] ['यूरी'], 'alt' => 'Alt text')); – Clive

+0

अच्छा लग रहा है। मुझे उन कार्यों का उपयोग शुरू करना चाहिए। – Kristoffer

18

मुझे डर लग रहा है, ऊपर से कोई भी समाधान सही हैं। वे Drupal मानकों का पालन नहीं करते हैं।

// 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']); 

अधिक यहाँ विवरण: http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way

+3

उपरोक्त कोड सही है। आम तौर पर ऊपर वर्णित अनुसार अधिकांश लोगों को ऐसा करने की आवश्यकता नहीं होती है, लेकिन यदि आप कोड लिखना चाहते हैं जो ड्रूपल मानकों का पालन करता है और जब चीजें बदली जाती हैं या जो भी हो जाती है तो तोड़ नहीं जाएगी, तो यह ज़ोर दिया नहीं जा सकता कि यह कितना महत्वपूर्ण है। कोड में वस्तुओं का जिक्र करते हुए $ ऑब्जेक्ट ['und'] [0] ['element'] बेहद खराब अभ्यास है। हमेशा field_get_items या समकक्ष का उपयोग करें। –

1

तुम भी Image URL Formatter मॉड्यूल का उपयोग कर सकते हैं।

Drupal field settings

बोनस:: यह क्रम में क्षेत्र स्वरूप बदलने के लिए केवल URL प्राप्त करने की अनुमति देता है यह रूप में अच्छी तरह विचार के साथ काम करता है:

enter image description here

0

छवि शैली यूआरएल पाने के लिए:

$field = field_get_items('node', $node, 'field_image'); 
$image_url = image_style_url('landingpage_slider', $field[0]['uri']); 
संबंधित मुद्दे