2013-06-28 30 views
0

以下是我的模板代碼:未定義子程序及主要:: ThrowTemplateError

<html> 
<head> 
<style> 

.table 
{ 
    display:table; 
    border-collapse:separate; 
    border-spacing:2px; 
} 
.thead 
{ 
    display:table-header-group; 
    color:white; 
    font-weight:bold; 
    background-color:grey; 
} 
.tbody 
{ 
    display:table-row-group; 
} 

.tr 
{ 
    display:table-row; 
} 
.td 
{ 
    display:table-cell; 
    border:1px solid black; 
    padding:1px; 
} 
.tr.editing .td INPUT 
width:100px; 
} 
</style> 
<script type = "text/javascript" src = "jquery.min.js"></script> 
<script> 
var counter = 0; 
var txt1 = "group_save"; 
function addNew() { 
// Get the main Div in which all the other divs will be added 
var mainContainer = document.getElementById('mainContainer'); 
// Create a new div for holding text and button input elements 
var newDiv = document.createElement('div'); 
// Create a new text input 
var newText = document.createElement('input'); 
newText.type = "input"; 
newText.name = txt1+counter; 
//newText.value = counter; 
// Create a new button input 
var newDelButton = document.createElement('input'); 
newDelButton.type = "button"; 
newDelButton.value = "Delete"; 
// Append new text input to the newDiv 
newDiv.appendChild(newText); 
// Append new button input to the newDiv 
newDiv.appendChild(newDelButton); 
// Append newDiv input to the mainContainer div 
mainContainer.appendChild(newDiv); 
counter++; 
// Add a handler to button for deleting the newDiv from the mainContainer 
newDelButton.onclick = function() { 
mainContainer.removeChild(newDiv); 
} 
} 
    function edit(element){ 
    var tr = jQuery(element).parent().parent(); 
    if(!tr.hasClass("editing")) { 
      tr.addClass("editing"); 
      tr.find("DIV.td").each(function(){ 
        if(!jQuery(this).hasClass("action")){ 
          var value = jQuery(this).text(); 

          jQuery(this).text(""); 
          jQuery(this).append('<input type="text" value="'+value+'" />'); 

        } else { 
          jQuery(this).find("BUTTON").text("save"); 
        } 
      }); 
    } else { 
      tr.removeClass("editing"); 
      tr.find("DIV.td").each(function(){ 
        if(!jQuery(this).hasClass("action")){ 
          var value1 = jQuery(this).find("INPUT").val(); 
          alert(value1); 
          jQuery(this).text(value1); 
          jQuery(this).find("INPUT").remove(); 
        } else { 
          jQuery(this).find("BUTTON").text("edit"); 
        } 
      }); 
    } 
} 
</script> 

</head> 
<body > 
<form name="group" method="post" action="process.cgi"> 
<div id="mainContainer"> 
<div><input type="button" value="Add" onClick="addNew()"></div> 
</div> 
<div><input type = "submit" value = "Save"></div> 
</form> 
[% IF count > 0%] 

<b>Details of Groups</b><br> 

<div class= "table"> 
<div class = "thead"> 
    <div class = "tr"> 

<div class = "td">ID</div> 
<div class = "td">GROUP NAME</div> 
<div class = "td">GROUP DESCRIPTION</div> 
<div class = "td">IS ACTIVE</div> 
<div class = "td"></div> 
</div> 
</div> 

<div class= "tbody"> 

[%- SET i = 0; 
WHILE i < id.size; -%] 

<form class = "tr"> 
<div class = "td">&nbsp; [% id.$i %]<br/></div> 
<div class = "td">&nbsp; [% group_name.$i %]<br/></div> 
<div class = "td">&nbsp; [% group_desc.$i %]<br/></div> 
<div class = "td">[% actv.$i %]<br/></div> 
<div class = "td action" ><button type="button" onclick="edit(this);">edit</button> </div> 
<form> 
[%-  SET i = i + 1; 
END -%] 
</div> 
</body> 
</html> 

而我跑我的CGI代碼,我得到了下面的模板error.i檢查了我的代碼,並沒有發現明顯的,這給error.could任何人請幫我追蹤這個錯誤。所以,我可以去其餘的修改文件。這就是我想保存更改的內容在數據庫中。

更新:

錯誤--- 未定義子程序&主要:: ThrowTemplateError叫在/var/www/html/centralbugzilla/groups.cgi線24

線24號是: $ template-> process(「list/group.html.tmpl」,$ vars) || ThrowTemplateError($模板 - >錯誤());

+0

哪個錯誤?請發佈:D – 2013-06-28 08:35:59

+0

我發佈了錯誤 –

+0

實際上你沒有一個名爲'ThrowTemplateError'的子程序。嘗試使用'$ template-> ThrowTemplateError' – 2013-06-28 08:50:13

回答

1

首先,你不應該假設人們會知道你正在使用的模板系統。它看起來像你正在使用模板工具包,但有許多用於Perl的模板引擎。

其次,這裏的模板是一個完整的紅色鯡魚。問題出在你的Perl代碼中。當模板無法成功處理時,您的代碼會調用一個名爲ThrowTemplateError的函數,但Perl無法在任何地方找到該函數。該功能在哪裏定義? (好吧,我想它可能看起來像問題是在你的模板,而不是代碼。你的模板有一些錯誤,這意味着TT無法處理它,因此調用缺少的函數。你的模板中的錯誤將意味着缺失的函數不再被調用,但它仍然缺失,下一次你不小心破壞你的模板時會再次出現問題,所以最好現在就修復它)

+1

我去錯誤,我沒有結束我的if循環 –

+0

Jenifer_justin:你是否修復了關於'ThrowTemplateError'的錯誤? – innaM

+0

@Jenifer_justin:這就是我爲什麼添加了我的最終(括號內)段落的原因。當您的模板中也存在錯誤時,您只會在Perl代碼中看到錯誤。但即使您修復了模板,Perl代碼中的問題仍然存在。 'ThrowTemplateError'子程序仍然缺失。你應該花時間來解決這個問題。 –

相關問題