更改 Drupal 7 上的页脚页面
在 Drupal 6 中,我的模块具有下一个功能,它将 JavaScript 插入页面的页脚,但在 Drupal 7 中,内容发生了变化。我该如何在 drupal 7 中执行下一个代码?
function myfunc_footer()
{
if(variable_get('myvar',1) && !drupal_match_path(drupal_get_path_alias($_GET['q']),
'admin/*'))
{
if ($somevar = variable_get('somevar',''))
{
return '<script src="'.$somevar.'" type="text/javascript"></script>';
}
else
{
drupal_set_message(t('something is wrong.'));
}
}
}
提前致谢
In Drupal 6, my module had this next function which inserted a javascript to the footer of the page, but in Drupal 7, stuff have changed. How can I do this next code in drupal 7?
function myfunc_footer()
{
if(variable_get('myvar',1) && !drupal_match_path(drupal_get_path_alias($_GET['q']),
'admin/*'))
{
if ($somevar = variable_get('somevar',''))
{
return '<script src="'.$somevar.'" type="text/javascript"></script>';
}
else
{
drupal_set_message(t('something is wrong.'));
}
}
}
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 Drupal 6 到 7,您的代码中没有任何变化...所有功能都是有效的,如果这适用于 Drupal 6,那么它没有理由不适用于 Drupal 7。
我不太明白您为什么要运行不过,针对路径别名的
drupal_match_path
,您应该针对 router 路径运行它,而不是 URL 路径:尝试一下,看看它是否可以解决您的问题,如果不能,您可以扩展一点关于你遇到什么错误?
编辑
感谢您的更新,您下面的第二条评论几乎是正确的,您只需要给渲染数组一个键:
您不需要指定
'#type' => 'markup'
作为markup
是默认值。然后确保您的模块(名为
myfunc
的模块)已明确安装,并清除缓存。从那里你应该不会有任何问题Nothing in your code has changed from Drupal 6 to 7...all of the functions are valid and if this worked for Drupal 6 there's no reason it wouldn't work for Drupal 7.
I don't really understand why you're running
drupal_match_path
against a path alias though, you should be running that against the router path, not URL path:Try that and see if it fixes your problem, if not could you expand a bit about what error you're getting?
EDIT
Thanks for the update, your second comment below is nearly right, you just need to give the render array a key:
You don't need to specify
'#type' => 'markup'
asmarkup
is the default.Then make sure your module (the one called
myfunc
) is definitely installed, and clear the caches. You shouldn't have any problems from there