如何在Text :: Xslate中级联包含的模板?

时间:2018-09-12 13:36:59

标签: perl templates text-xslate

Text::Xslate中是将cascade特定模板(或在其他模板引擎中包装)特定模板为主模板的好方法。也可以将include个公共块放入模板中。

我想将include块化成特定模板,其中cascade成为主模板,但是以某种方式include d模板具有可替换的部分(around关键字)main中的某些命名部分。

简化的测试用例

main.pl

use strict;
use warnings;

use FindBin qw($Bin);
use Text::Xslate;

my $tx = Text::Xslate->new(
    path => [ "$Bin/template" ],
);

print $tx->render( 'some.tx' );

template / some.tx

: cascade main

: around some -> {

some text 1

: include included;

some text 2
: }

template / main.tx

MAIN template

: block main -> { 
  main DEFAULT text, should replaced with included.tx one
: } # 

: block some -> { 
: } # 

template / included.tx

: around main -> { 
  this should come from included but does not
: }  

included successfully into some.tx

所需的输出

MAIN template

  this should come from included but does not


some text 1


included successfully into some.tx


some text 2

如果我在some.tx中使用它,则输出中的第三行不正确

: around main -> { 
  this should come from included but does not
: }  

有效。

但是如何包含应该层叠到主模板中的块?

1 个答案:

答案 0 :(得分:0)

尝试cascade ... with

template / some.tx

: cascade main with included
: around some -> {
some text 1
: include included;
some text 2
: }