2012-05-20 157 views
0
l(t('Edit'), 'node/' . $node->nid . '/webform/components/' . $cid, array('query' => drupal_get_destination())), 

我想用圖像替換單詞「編輯」,但是當我把圖像src放在那裏時,它顯示爲文本。我應該使用不同的功能嗎?用php替換文本鏈接圖像

我使用Drupal作爲我的框架。

感謝來自noob。

回答

1

該按鈕應該有自己的類,例如action_button或ID如edit_button。現在使用CSS來隱藏文本,並使用在其位置的背景圖像,如下圖所示:

.action_button, #edit_button { 

    /* Hide Text */ 
    text-indent: -9999px; 

    display: block; 
    background: url('edit_button.png') no-repeat; 

    /* Set width and height equal to the size of your image */ 
    width: 20px; 
    height: 20px; 
} 

編輯1:

更改你的代碼的下方,使用上面的CSS:

l(t('Edit'), 'node/'.$node->nid.'/webform/components/'.$cid, array('attributes' => array('id' => array('edit_button')), 'query' => drupal_get_destination())); 

編輯2 [FINAL]:

傳遞htmlTRUEl()方法的array parameter可以使我們能夠使用first parameterimg標記,而不是顯示只是文本鏈接:

l('<img src="edit_button.png" alt="Edit" />', 'node/'.$node->nid.'/webform/components/'.$cid, array('query' => drupal_get_destination(), 'html' => 'TRUE')); 
+0

謝謝維沙爾,但是文本不會有它自己的階級在網絡表單模塊設置Drupal的 - 我認爲這將是更容易直接設置圖像在PHP中? – Jeremy

+0

決定了這一點和增加的類,你的CSS工作得很好。謝謝! – Jeremy

+0

查看編輯答案! – Vishal

2
做到這一點

最好的辦法是結合l()theme_image()

print l(theme_image(array('path' => 'edit_button.png', 'attributes' => array('title' => t('Edit')))), 'node/' . $node->nid . '/webform/components/' . $cid, array('query' => drupal_get_destination(), 'html' => TRUE)); 

您還應該使用drupal_get_path()作爲圖像路徑的前綴。 這樣你將完全適用於Drupal編碼標準,並讓你的生活更輕鬆。

0

這是我實現的最佳途徑:

list($nodeImage) = field_get_items('node', $node, 'uc_product_image'); 

$style_array = array('path' => $nodeImage['uri'], 'style_name' => 'MY_IMAGE_STYLE'); 

$render_node_image = theme('image_style', $style_array); 
$render_node_image_WITH_LINK = l($render_node_image, 'node/' . $node->nid, array('html' => TRUE)); 

print $render_node_image_WITH_LINK