【问题标题】:Template Toolkit - get variables from inserted fragment before it's inserted模板工具包 - 在插入之前从插入的片段中获取变量
【发布时间】:2014-03-24 00:00:56
【问题描述】:

在我正在创建的 html 页面的某处,我从其他文件中插入了一个模板,该模板本身包含 TT 变量定义。片段“specials.htm”

[% specials = 123 %]

但我需要在主页上使用这个变量之前包含所述片段。主页:

<p>Specials are [% specials %]
<!-- some html -->
[% PROCESS specials.htm %]

我尝试在 BLOCK 中处理此包含,然后稍后插入此块 - 但由于某种原因这不起作用:

[% BLOCK specblock %]
  [% PROCESS specials.htm %]
[% END %]

<p>Specials are [% specials %] <!-- No luck! -->

<!-- some html -->

[% INCLUDE specblock %]

当前的解决方法是 - 使用 div 和 css,因此 div 通过为其分配绝对位置出现在默认位置之前的页面上。但这有点蹩脚。

【问题讨论】:

    标签: html css perl templates toolkit


    【解决方案1】:

    如果我对问题的理解正确,那么如何使用匿名 BLOCK 将模板片段的输出捕获到变量中:

    [% output = BLOCK %]
        [% PROCESS specials.htm %]
    [% END %]
    
    <p>Specials are [% specials %]
    
    <!-- some html -->
    
    [% output %]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-21
      • 1970-01-01
      相关资源
      最近更新 更多