我想在我的drupal网站上显示两个不同的徽标:一个用于首页,一个用于内页。
if (drupal_is_front_page()) {
$variables['logo']=drupal_get_path('theme', 'hanna') . '/images/logo.png';
}
else {
$variables['logo']=drupal_get_path('theme', 'hanna') . '/images/logo-inner.png';
}
这适用于首页和任何以websiteurl / page为URL的页面;但是,它不适用于URL类似于websiteurl / custompath / page的页面。
我认为问题在于具有自定义URL路径的页面的相对性。
你有什么想法吗?
答案 0 :(得分:7)
您可以使用drupal global $base_url
获取安装的绝对路径,并将图像的绝对路径附加到其中。
请参阅the Drupal Documentation to this topic。
您也可以使用base_path()来获取路径。
答案 1 :(得分:4)
重要的是要注意:
base_path()
返回安装drupal网站的文件夹的相对路径。$base_url
返回您的域路径,不带斜杠。因此,要确保拥有正确的绝对路径,您必须同时使用它们:
//example to get an image absolute path
global $base_url;
$image_path = $base_url . base_path() . path_to_theme() . '/images/my-image.png';
//$image_path will output something like: "http://www.my-domain.com/sites/all/themes/your-theme-name/images/my-image.png"
注意:path_to_theme
类似于$ base_url,没有尾随斜杠。