从另一个模板调用模板 [英] calling template from the other template

查看:105
本文介绍了从另一个模板调用模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Catalyst MVC框架来创建数据库的网页.我不是这样的全职程序员.但是我知道perl和java的基础.我是生物学家.我写了一个有表的模板文件(view.tt).我需要将此表的内容链接到另一个在另一个模板文件中编写的表.我无法链接这两个模板(因为我无法正确生成网址).谁能帮忙或指导我解决此问题.

I am working on Catalyst MVC framework to create a web page for a database. I am not a full time programmer as such. But I know basics of perl and java. I am a biologist. I have written a template file(view.tt) which is having a table. I need to link the contents of this table to another table which is written in one more template file. I am not able to link these two templates(as I am not able to generate the url properly). Can any one help or guide me to resolve this issue.

以下代码用于第二个模板文件:

The following code is for the second template file:

<h4>Analyses Table</h4>

<table id="analysis_table" width="90%">

<thead>

<tr>
  <th align="center" valign="center">Dataset</th>
  <th align="center" valign="center">Tissue</th>
  <th align="center" valign="center">Expression</th>
  <th align="center" valign="center">Analysis</th>
</tr>

</thead>
<tbody>
[% FOREACH result IN plets -%]
  [% IF result.analysistypename == 'Cancer' -%]

    [% matches = result.datasetname.match('(\w+) (\w+)') %]
    <tr>
    <td align="left" valign="top">[% result.datasetname %]</td>
    <td align="left" valign="top">[% result.expression %]</td>
    <td align="left" valign="top">[% result.datatype %]</td>
    <td align="left" valign="top">[% result.generankpercentile %]</td>
    </tr>
  [% END -%]
[% END -%]

</tbody>

<tfoot>

<tr>
  <th align="center" valign="center">Dataset</th>
  <th align="center" valign="center">Tissue</th>
  <th align="center" valign="center">Expression</th>
  <th align="center" valign="center">Analysis</th>
</tr>

</tfoot>

</table> 

下面的代码在我的第一个模板中,该模板具有要被超链接的表(view.tt)

The following piece of code is in my first template which has the table to be hyperlinked(view.tt)

<h4>Analyses Summary table</h4>

<table id="score_table" width="50%">

<thead>

<tr>
<th align="centre" valign="centre"> Analysis Type</th>
<th align="centre" valign="centre">Score</th>
</tr>

</thead>

<tbody>

[% FOREACH score IN gene.whs -%]

[% plots = [ ['Cancer', score.cancer_vs_normal_over, score.cancer_vs_normal_under],
['Bladder cancer', score.bladder_cancer_over, score.bladder_cancer_under],
['Brain and CNS cancer', score.brain_and_cns_cancer_over, score.brain_and_cns_cancer_under],
['Breast Cancer', score.breast_cancer_over, score.breast_cancer_under],
['Cervical Cancer', score.cervical_cancer_over, score.cervical_cancer_under],
['Colorectal cancer', score.colorectal_cancer_over, score.colorectal_cancer_under],
]
%]


[% FOREACH plot IN plots %]
<tr>
<td> [% pl0t.0 %]</td>
<td> [% pl0t.1 %] </td>
<td> [% pl0t.2 %] </td>
<td> [% (pl0t.1 + 5 ) / (plot.2 + 5) | format('%5.2f') %] </td>
</tr>
[% END %]

[% END %]

</tbody>

<tfoot>
<tr>
<th align="centre" valign="centre"> Analysis Type</th>
<th align="centre" valign="centre">Score</th>
</tr>
</tfoot>

</table>

您好,Ret,非常感谢,对于您的回复深表歉意.如您所了解,我的目标是在摘要表和加载了结果的第二张表之间建立一个实时"链接.我以另一种方式链接了模板.我不得不将第一个模板中的超链接链接到第二个模板.我的超链接位于foreach循环中,看起来像这样.

Hi Ret, Thanks a lot and sorry for late reply. As you have understood my aim is to have a 'live' link between the summary table and a second table loaded with results. I have somehow linked the templates by another way.I had to hyperlink in first template to second template. My hyperlinking is in the foreach loop which looks something like this.

[% FOREACH plot IN plots %]
    <tr>
    <td><a href="[% c.uri_for(c.controller('gene').action_for('sample'))%]/[% plot.0 %]>[% plot.0 %]</a></td>
    <td> [% pl0t.1 %] </td>
    <td> [% pl0t.2 %] </td>
    <td> [% (pl0t.1 + 5 ) / (plot.2 + 5) | format('%5.2f') %] </td>
    </tr>
    [% END %]

此行正确链接到第二个模板(sample.tt).第二个模板包含一系列表.当在第一个表上单击超链接时,应显示与该链接相对应的表.我已经成功链接了模板.我还在控制器(gene.pm)中创建了一个子例程,也用于链接模板.我在实现目标时遇到了问题.第二个模板(sample.tt)中的html部分运行正常,但是模板工具包未运行.我可以在url中看到更改,但是在页面中却没有反映出来.

This line is linking correctly to the second template(sample.tt). The second template contains a series of tables. when the hyperlink is clicked on the first table, the table corresponding to that link should be displayed. I have successfully linked the templates. I have created a sub routine in my controller(gene.pm) also for the purpose of linking the templates. I am facing a problem in achieving my goal. The html part inthe second template(sample.tt) is functioning properly,but the template toolkit is not functioning. I am able to see the change in the url but in the page it is not reflected.

下面是第二个模板的子例程:

Below is the subroutine for the second template:

sub sample :Path('sample'):Args(1) {
         my($self,$c,$plot)=@_;
         my @plets = $c->model('GeneDB::genewhs')->search({
         Analysistypename => @plet,
 });
         $c->stash->{plets}=\@plets;
         $c->stash->{template}='gene/sample.tt';

 }

如果问题仍然不清楚,请让我知道...我将不得不将其清除..

If in case the question is not clear, please let me know...i would be obliged to clear it..

先谢谢了.

推荐答案

可以在当前正在处理的模板中简单地PROCESSINCLUDE另一个模板,但这不允许用户交互.我认为您的目标是在摘要表和第二张表之间建立一个实时"链接,并在从第一张表中进行某些选择后加载结果?您的问题还不太清楚.

It is possible to simply PROCESS or INCLUDE another template in the one currently being processed, but this doesn't allow for user interaction. I take it your aim is to have a 'live' link between the summary table and a second table loaded with results following some selection from the first? It's not completely clear from your question.

但是,如果我理解正确,您将需要(至少)做以下两件事之一:

But if I understand correctly, you will need to do one of (at least) two things:

  1. 将所有结果加载到一系列表中,并向每个表添加一个ID和CSS类以指示其类型.使用jQuery(或类似语言)隐藏所有内容,并通过在摘要表中单击来显示相关表.如果结果量不是很大,这将起作用,这意味着您不需要掌握AJAX. (您也可以将所有结果放在一个表中,并使用CSS类来标识类型.)
  2. 编写Catalyst Action,该Catalyst Action接收标识返回结果所需的任何参数,并将其作为JSON数组返回.调用函数负责表的布局.除非您通常对jQuery,AJAX和Javascript非常熟悉,否则所有结果的数量都令人望而却步.

已经说过#2了,看来您已经隐瞒了所有结果.它们如何链接尚不清楚. (我不禁认为此数据应该在Catalyst端进行规范化,而不是使用模板端的plots数组进行解码.)因此,假设您选择的是选项#1,则需要类似以下内容:

Having said #2, it looks like you've already got all the results stashed anyway. How they're linked is less clear. (I can't help thinking this data should be normalised on the Catalyst side, rather than decoded with the plots array on the template side.) So assuming you go with option #1, you'll need something like:

[%- 
    #add a 'key' field with no spaces suitable for jQuery as the last element
    plots = [
        ['Cancer', score.cancer_vs_normal_over, score.cancer_vs_normal_under, 'cancer'],
        ['Bladder cancer', score.bladder_cancer_over, score.bladder_cancer_under, 'bladder-cancer' ],
-%]

[% FOREACH plot IN plots %]
<tr>
<td class="linktoresults" rel="#[%plot.3%]"> [% plot.0 %]</td>
...
[% END %]

[%- FOREACH ... # It's just not clear how plots relate to gene.whs
    SET rel = ... # how this result links back to the plot array from earlier.
    PROCESS "secondarytable.tt";
    END;
-%]

<script src="jquery.js"></script>
<script>
    $(document).ready(function({
        $(".linktoresults").click(function({
             id = $(this).attr('rel');
             $(".analysis_table").hide(); // hide all tables
             $(id).show(); // show the relevant one for this item
        });
    });
</script>

您的secondarytable.tt模板需要具有:

And your secondarytable.tt template needs to have:

<table class="analysis_table" id="[%rel%]" width="90%">

...因此单击功能可以链接到下级表.

...so the click function can link to the subordinate tables.

希望这些代码段可以帮助您朝着正确的方向发展.恐怕plotsgene.whs之间的关系还不够清楚,我无法为您提供更多.

Hopefully these code snippets will give you a push in the right direction. The relationship between plots and gene.whs is not clear enough for me to give you much more, I'm afraid.

这篇关于从另一个模板调用模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆