l(t('Edit'), 'node/' . $node->nid . '/webform/components/' . $cid, array('query' => drupal_get_destination())),
我想用图像替换单词“编辑”,但是当我把图像src放在那里时,它显示为文本。我应该使用不同的功能吗?用php替换文本链接图像
我使用Drupal作为我的框架。
感谢来自noob。
l(t('Edit'), 'node/' . $node->nid . '/webform/components/' . $cid, array('query' => drupal_get_destination())),
我想用图像替换单词“编辑”,但是当我把图像src放在那里时,它显示为文本。我应该使用不同的功能吗?用php替换文本链接图像
我使用Drupal作为我的框架。
感谢来自noob。
该按钮应该有自己的类,例如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]:
传递html
为TRUE
到l()
方法的array parameter
可以使我们能够使用first parameter
为img
标记,而不是显示只是文本链接:
l('<img src="edit_button.png" alt="Edit" />', 'node/'.$node->nid.'/webform/components/'.$cid, array('query' => drupal_get_destination(), 'html' => 'TRUE'));
最好的办法是结合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编码标准,并让你的生活更轻松。
这是我实现的最佳途径:
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
谢谢维沙尔,但是文本不会有它自己的阶级在网络表单模块设置Drupal的 - 我认为这将是更容易直接设置图像在PHP中? – Jeremy
决定了这一点和增加的类,你的CSS工作得很好。谢谢! – Jeremy
查看编辑答案! – Vishal