添加HTML到Drupal封闭? [英] Adding HTML to Drupal closure?

查看:119
本文介绍了添加HTML到Drupal封闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要添加javascript,您可以使用:

To add javascript, you can use:

drupal_add_js

类似于css:

drupal_add_css

但是如果我只想在我的页面的末尾添加html。也就是说

But what if I just want to add html at the end of my page. I.e. Add a div with some text in it at the end of the page?

推荐答案

很多建议都可以在这里工作,如果你想要的修改为基于主题,但如果你想让它来自一个模块,使用块区域,页面模板或页面预处理不会剪切它,因为你绑定对主题的更改。 strong>

A lot of suggestions here work if you want your alteration to be theme-based, but if you want this to come from a module, using a block region, page template or page prepocess won't cut it, because you're tying the alteration to the theme.

从模块的角度来看,以下选项是最好的:

From a modular standpoint, the following options are best:

hook_footer / strong> - http://api.drupal.org/api/function/hook_footer/6 :: my_module_footer()应该返回一个HTML字符串,甚至可以是javascript。例如。

hook_footer() -- http://api.drupal.org/api/function/hook_footer/6 :: my_module_footer() should return a string of HTML, which can even be javascript. E.g.

function my_module_footer(){

    return "<script type='text/javascript'>//your script</script>"

}

您可以使用drupal $ _GET ['q']获取页面URL,并返回页面URL的条件。

You can use drupal $_GET['q'] to get the page URL and have that return be conditional for the page URL.

否则,我有时使用$ GLOBALS [_ add_my_footer]作为布尔值,并将其设置在模块中的各个点,然后在hook_footer是真的。

Otherwise, I sometimes use $GLOBALS["_add_my_footer"] as a boolean, and set it at various points in the module, then in hook_footer(), see if it is true.

drupal_add_js - api.drupal.org/api/drupal/includes --common.inc / function / drupal_add_js / 6 ::你可以通过将$ scope参数设置为footer来将javascript添加到页脚 - 例如

drupal_add_js -- api.drupal.org/api/drupal/includes--common.inc/function/drupal_add_js/6 :: You can use this to add javascript to the footer by setting the $scope parameter to "footer" -- e.g.

function my_module_init(){

    $script = "your script "; // notice no <script> tags
    drupal_add_js($script, 'inline', 'footer');
    // you can also use this function to grab a .js file

}


注意,我把drupal_add_js放到hook_init() - 我这样做,因为如果你不这样做,脚本可能会丢失,当使用Drupal的侵略性缓存功能。


Note that I put that drupal_add_js into hook_init() -- I did that because if you don't, the script could get lost when using Drupal's aggressive caching feature.

不幸的是,drupal_add_css没有$ scope参数

Unfortunately, there is no $scope parameter for drupal_add_css

这篇关于添加HTML到Drupal封闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆