将HTML添加到Drupal关闭?

编程入门 行业动态 更新时间:2024-10-10 09:25:52
本文介绍了将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() - api.drupal/api/function/hook_footer/ 6 :: my_module_footer()应该返回一个HTML字符串,甚至可以是javascript。例如。

hook_footer() -- api.drupal/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/api/drupal/includes --common.inc / function / drupal_add_js / 6 ::您可以通过将$ scope参数设置为footer来将其添加到页脚中 - 例如

drupal_add_js -- api.drupal/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关闭?

本文发布于:2023-11-09 04:06:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571356.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HTML   Drupal

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!