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

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

问题描述

要添加javascript,您可以使用:

To add javascript, you can use:

drupal_add_js

类似于css:

drupal_add_css

但是,如果我只想在页面末尾添加HTML,该怎么办?即在页面末尾添加一些div,其中包含一些文本?

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() - 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来将其添加到页脚中 - 例如

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天全站免登陆