使用 drupal 和 angularjs 的动态基础 url
Dynamic base url with drupal and angularjs
我已经在 drupal 7 中创建了 2 个 angular 应用程序,例如“example.com”、“example.com/app1”、“example.com/app2”。
example.com 是我的主要站点。因此,当我设置 html5 pushstate enable 以删除 angular 应用程序中的哈希时,我从 angularjs 中得到了 nobase 错误。因为,
<base href="">
需要启用 angularjs html5 pushstate。
我的问题是,由于我在这个 drupal 站点中有多个 angualr 应用程序,我如何为“/app1”和“app2”动态添加条件基础 url?
有人可以帮助我吗?等待答复。谢谢
您可以通过以下方式将基本元素添加到您的站点:
YOUR_THEME_NAME_preprocess_html(&$variables, $hook) {
$url = 'default';// default url
if($application1) {// your condition for app1
$url = 'app1';
} elseif($application2) {// your condition for app2
$url = 'app2';
}
$data = array(
'#tag' => 'base',
'#attributes' => array(
'href' => $url,
),
);
drupal_add_html_head($data, 'base_href');
}
把它放进你的template.php
我已经在 drupal 7 中创建了 2 个 angular 应用程序,例如“example.com”、“example.com/app1”、“example.com/app2”。
example.com 是我的主要站点。因此,当我设置 html5 pushstate enable 以删除 angular 应用程序中的哈希时,我从 angularjs 中得到了 nobase 错误。因为,
<base href="">
需要启用 angularjs html5 pushstate。
我的问题是,由于我在这个 drupal 站点中有多个 angualr 应用程序,我如何为“/app1”和“app2”动态添加条件基础 url?
有人可以帮助我吗?等待答复。谢谢
您可以通过以下方式将基本元素添加到您的站点:
YOUR_THEME_NAME_preprocess_html(&$variables, $hook) {
$url = 'default';// default url
if($application1) {// your condition for app1
$url = 'app1';
} elseif($application2) {// your condition for app2
$url = 'app2';
}
$data = array(
'#tag' => 'base',
'#attributes' => array(
'href' => $url,
),
);
drupal_add_html_head($data, 'base_href');
}
把它放进你的template.php