Drupal模块 - 是不是

Ste*_*fan 3 drupal drupal-7

我以前没有为Drupal开发任何模块,我想我真的只想要一些验证,如果这是"正确的",我希望有人可以提供帮助.它是为Drupal 7开发的,用于将javascript文件注入页面的页脚

sessioncam.module文件:

<?php
/**
* @file
* The code below adds the sessioncam.js file in the footer section of your site
*/
?>

<?php
drupal_add_js(drupal_get_path('module', 'sessioncam') .'/sessioncam.js', array('type' => 'external', 'scope' => 'footer')) ;
?>
Run Code Online (Sandbox Code Playgroud)

sessioncam.info文件:

name = SessionCam
description = Module to inject the SessionCam recorder code
core = 7.x
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏

Cli*_*ive 6

不太对劲.调用drupal_add_js()不应该在全局范围内,而应该在钩子函数中.如果你想在每一页上添加它hook_init()都是合适的:

function sessioncam_init() {
  drupal_add_js(drupal_get_path('module', 'sessioncam') .'/sessioncam.js', array('type' => 'external', 'scope' => 'footer')) ;
}
Run Code Online (Sandbox Code Playgroud)

  • 实际上我错过了你添加到页脚的事实,我认为你不能在信息文件中指定它,所以最好使用hook方法 (2认同)