【发布时间】:2018-12-12 18:16:51
【问题描述】:
当前使用以下方式渲染图像:
$desktop_img = theme('image', array(
'path' => drupal_get_path('module', 'my_awesome_module') . '/images/desktop.png',
'width' => 20,
'height' => 20,
'alt' => t('View pc version'),
));
呈现为:
<img src="http://myawesome.site/sites/all/modules/custom/my_awesome_module/images/desktop.png" width="20" height="20" alt="View pc version" />
但我想要的是:
<img src="/sites/all/modules/custom/my_awesome_module/images/desktop.png" width="20" height="20" alt="View pc version" />
现在我们有一个解决方案可以使用:
function another_awesome_module_file_url_alter(&$uri) {
// Get outta here if there's an absolute link
if (strpos($uri, '://') !== FALSE) {
return;
}
// If the path includes references a gif/jpg/png images elsewhere
if (strpos($uri, conf_path()) !== FALSE ||
preg_match('/\.(jpg|gif|png)/i', $uri)) {
$uri = $GLOBALS['base_path'] . ltrim($uri, '/');
}
}
返回所有文件的绝对路径。所以我的问题是,在 theme_image 中是否有一种仅针对手头的图像执行此操作的方式,而不是更改所有文件的路径?
【问题讨论】:
标签: drupal-7 hook relative-path absolute-path