【问题标题】:making clean page via page.tpl.php通过 page.tpl.php 制作干净的页面
【发布时间】:2010-06-07 04:55:09
【问题描述】:

我有一个 Drupal 模块通过 hook_menu() 创建一个页面。我正在努力使页面没有多余的 html 输出,只有我想要的。您可以在此处查看页面,http://www.thomashansen.me/chat/thomas。如果您查看源代码,您会在末尾看到一个奇怪的脚本标签。

我的 page-chat.tpl.php 是这样的,

<?php
// $Id$
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
<head>
</head>
<body>
<?php print $content; ?>
</body>
</html>

那个脚本标签是从哪里来的?我该如何摆脱它?如果您需要更多信息,请询问。

【问题讨论】:

    标签: php javascript jquery drupal drupal-6


    【解决方案1】:

    您在评论中提到的内容来自devel_themer(开发模块的一部分)模块。它正在扩展全局 Drupal js 变量。

    Drupal 创建一个全局 Drupal js 变量,它保存不同的信息。模块和主题可以使用它来创建一些包含 Drupal 信息的变量,它们需要这些信息,例如 API 密钥或变量,以确定脚本的行为方式。

    devel_themer 将有关输出的不同部分的信息发布到脚本变量。这就是它使您可以检查标记并查看用于生成输出的主题函数或模板以及如何覆盖它的方式。它会创建很多span 标签,并显示您在脚本中看到的信息,具体取决于您将鼠标悬停在哪个标签上。

    【讨论】:

    • 谢谢,就是这样。关掉它,很棒!
    【解决方案2】:

    如果你在谈论这个:

    <script type="text/javascript" src="/sites/all/modules/google_analytics/googleanalytics.js?n"></script> 
    <script type="text/javascript"> 
    <!--//--><![CDATA[//><!--
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    //--><!]]>
    </script> 
    <script type="text/javascript"> 
    <!--//--><![CDATA[//><!--
    try{var pageTracker = _gat._getTracker("UA-15854642-1");pageTracker._trackPageview("/403.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer);} catch(err) {}
    //--><!]]>
    </script>
    

    Google Analytics module 添加的是 Google Analytics(分析)代码。您可以禁用该模块以删除代码。

    【讨论】:

    • 不,我说的是 www.thomashansen.me/chat/thomas 末尾出现的脚本,它看起来像“
    【解决方案3】:

    抱歉,该页面需要查看权限。无论如何,脚本现在已经消失了。也许只是时间修复它。

    【讨论】:

      【解决方案4】:

      如果你想要 Drupal.settings 而不是其他脚本,你可以做的是你的 template.php 中的设置:

      function THEME_preprocess_page(&$vars) {
        //get javascript Drupal.settings
        $scripts = drupal_add_js(NULL,'settings','header');
        $js_settings['setting'] = $scripts['setting'];
        $vars['js_settings'] = drupal_get_js(null, $js_settings);
      }
      

      在你的 page.tpl.php 中通过

      打印它们之后
      <?php print $js_settings ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-12-19
        • 1970-01-01
        • 1970-01-01
        • 2015-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-18
        相关资源
        最近更新 更多