簡體   English   中英

無法將perl哈希返回到模板工具包文件中

[英]Unable to return the perl Hash into the template toolkit file

提前致謝。 我正在嘗試使用模板工具包文件顯示文件列表。在此之前,我將哈希從perl文件返回到.tt(模板工具包文件)文件中。 但是條件沒有執行,而且我也無法顯示文件列表。 供您參考,我正在提供文件。

Perl文件(Example.pm):

sub example{ 
    my $path = "/sa2/tools/jayaram_delete";
    if (chdir($path)) {
        @files = glob "*";//I am getting the list of files
    } else {
        @files = ();
    }

    $run{'files'} = \@files;
    $run{'testing'}= 'files';

    return 'site/screen/screen.tt',\%run;
}

模板工具包文件:(Example.tt)

//This is The condition to display the Upload functionality in the .tt file
            [% IF screenName == 'Resource Management' %]
//This is the code given in Stackoverflow,for displaying the list of files getting from    perl file to .tt file.But this functionality is not working in this .tt file.
[% files %]
[% FOREACH n IN files %]
    [% n %]
    [% END %]
//This is the Table format to display the Upload functionality in the .tt file.
<table id='dataTableExample' class=dataTable cellpadding=01 cellspacing=01>

        <tr class=verification style="text-align:left;">
            <th colspan="2">Instrumentation Configuration</th>
        </tr>
    <tr class=controlTableDataRow>
                                    <td class=controlTableCommandCell>
                                             <form    action='/sa/site/screen/testresults/ajaxTab/test/[% parentid %]/[% id %]' method='post'   enctype="multipart/form-data" target='file_upload'>
                                                    <input type="file"  name="uploadFile" size=30>
                                                    <input type="submit" name="submit" value="Upload">
                                                    <iframe id='file_upload' name='file_upload' style="display:none" src='about:blank' onload="if (file_upload.location.href != 'about:blank') uploadStatus(this)" >
                                                    </iframe>
                                            </form>
                                    </td>
                            </tr>
//This is the sample code to display in the .tt file
    <table class=propertyTable cellpadding=5 cellspacing=0>
    <tr class=propertyTableHeaderRow>
            <th>FileName</th>
            <th>Last Modified Date</th>
    </tr>
    </table>
[% END %]

For your reference i am providing the complete file,please help to solve this problem  for displaying the list of files in .tt file.

此構造可以很好地滿足您的目標:

use strict;
use warnings;

use Template;

my @files = glob "*";
my $tt = Template->new();
my $va = {
    files => \@files
};
$tt->process('my.tt', $va);

在my.tt文件中:

[% FOREACH n IN files %]
[% n %]
[% END %]

我意識到這是一個非常老的問題,但是我碰到了這個問題,並且相信我看到了這個問題。 看起來您的代碼在結尾處有一個額外的[%END%]上限。 我將這段代碼放入模板中,它執行了與您所看到的相同的操作。 刪除了最后一個[%END%],我得到了輸出。 顯然,由於我沒有進行處理,因此它不是您想要的輸出,但是它解決了TT消隱的問題。 我確定您的問題早已解決,但是希望這可以在將來為其他人節省一些麻煩。 那些無賴標記可能會使TT感到痛苦。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM