2010-06-07 48 views
0

我有一個Drupal模塊,通過hook_menu()創建一個頁面。我正在努力使頁面沒有多餘的html輸出,只有我想要的。您可以在這裏查看頁面,http://www.thomashansen.me/chat/thomas。如果你看看源代碼,你可以在最後看到一個奇怪的腳本標籤。通過page.tpl.php製作乾淨的頁面

我的頁面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> 

剛纔那個腳本標籤是從哪裏來的?我該如何擺脫它?如果您需要更多信息,請詢問。

回答

0

你在評論中提到的內容來自devel_themer(devel模塊的一部分)模塊。它擴展了全球Drupal js的可變性。

Drupal創建了一個全局的Drupal js變量,它包含不同的信息。模塊和主題可以使用它來創建一些變量,包括他們需要的來自Drupal的信息,例如API鍵或變量,以確定腳本應該如何表現。

devel_themer將關於輸出的不同部分的信息發佈到腳本變量。這就是它使您可以檢查標記並查看哪些主題函數或模板用於生成輸出以及如何覆蓋它。它會創建大量span標籤,並顯示您在腳本中看到的信息,具體取決於您使用鼠標懸停的信息。

+0

謝謝,就是這樣。關掉它,太棒了! – Thomas4019 2010-06-08 19:45:40

0

如果你談論的是這樣的:

<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添加谷歌Analytics(分析)代碼。您可以禁用該模塊以刪除代碼。

+0

頭沒有我說的是這對www.thomashansen.me/chat/thomas 它看起來像「<腳本類型=」文/ JavaScript的」年底出現的腳本> jQuery.extend(Drupal.settings,{「thmr_5」:{「name」:「theme_menu_i 「tem_link」,「type」:「func」,「duration」:0.51,「used」:「theme_menu_item_link」,「candidates」:[「scaccarium_menu_item_link」,「phptemplate_menu_item_link」,...「 – Thomas4019 2010-06-07 05:08:08

+1

看起來像你啓用了Theme Developer模塊。關掉它,再看看。 – lazysoundsystem 2010-06-07 14:50:59

+0

謝謝,就是這樣。 – Thomas4019 2010-06-08 19:45:23

0

對不起,該頁面需要查看權限。無論如何,劇本現在消失了。也許只是時間修復它。

0

如果你想Drupal.settings但不是otther腳本,你可以做的就是這樣在你的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 ?> 
相關問題