Chinaunix首页 | 论坛 | 博客
  • 博客访问: 55101
  • 博文数量: 21
  • 博客积分: 1765
  • 博客等级: 上尉
  • 技术积分: 205
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-13 21:25
文章分类
文章存档

2011年(15)

2008年(6)

我的朋友

分类: Python/Ruby

2011-07-18 23:10:09

来源:


I've opted for the third method. First I created a file called external-js.tpl.php in my theme directory, containing this:

<script type="text/javascript" src="">
?>

Then, in my template.php file, I created a pre-process function that loads that into a variable and adds the appropriate JS function call to $footer:

function Nefertari_preprocess_page(&$vars){
   
$path = drupal_get_path('theme', 'Nefertari');
   
$vars['external_js'] = theme_render_template($path.'/external-js.tpl.php', $vars);
   
$vars['footer'] .= '';
}
?>

Lastly, I modified page.tpl.php to print the variable $external_js right after $script in the header. I could also have printed it right before the footer, and that might have been better for performance. There's actually a module for Google Analytics already, but it doesn't fit my needs very smoothly (it's designed for single sites, when I'm working with a multi-site install of nearly a hundred distinct Drupals).

阅读(674) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~