在Text::Xslate中是cascade
将特定模板(或在其他模板引擎中包装)到主模板的好方法。也可以将include
公共块放入模板中。
我想将include
特定的模板分块到cascade
主模板中,但在某种程度上,include
d 模板的部分替换(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
: }
有用。
但是如何包含应该级联到主模板的块?