4

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

我想将include特定的模板分块到cascade主模板中,但在某种程度上,included 模板的部分替换(around关键字)main 中的一些命名部分。

简化的测试用例

主文件

use strict;
use warnings;

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

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

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

模板/some.tx

: cascade main

: around some -> {

some text 1

: include included;

some text 2
: }

模板/main.tx

MAIN template

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

: block some -> { 
: } # 

模板/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
: }  

有用。

但是如何包含应该级联到主模板的块?

4

1 回答 1

0

尝试cascade ... with

模板/some.tx

: cascade main with included
: around some -> {
some text 1
: include included;
some text 2
: }
于 2019-01-04T07:59:58.247 回答