我们有一个共同的页眉/页脚模板作为父模板,我们将重用100个子模板。扩展指令不支持这个..。
当我浏览Rythm文档时,我找到了一种通过include/invoke指令来实现这一目标的方法,但是include/invoke指令的主要目的是调用公共函数。通过将主模板内容与呈现指令作为父模板和页眉/页脚模板作为子模板,扩展指令支持相反的方式,但实时使用完全不同。
这就是我的理解对吗?有办法解决我的问题吗?
编辑:
为了实现这个目标,我编写了如下代码:
footer.html
@def header1() {
<h3>This is footer1 section</h3>
}
@def header2() {
<h3>This is footer2 section</h3>
}template1.html
@include("footer.html")
@args String who
<html>
<head>
<title>Hello world from Rythm</title>
</head>
<body>
<h1>Hello @who</h1>
@if(footer.equals("footer1){
@header1();
} else {
@header2();
}
</body>
</html>我所做的是,在include/invoke方法调用的帮助下,我得到了结果,但是当我使用extends时,它不起作用。如果可能的话,你能用扩展来解决我的问题吗?
发布于 2016-10-21 10:17:41
要使用@extends实现同样的效果,您应该有:
layout.html
<html>
<head>
<title>Hello world from Rythm</title>
</head>
<body>
@render()
</body>
</html>header1.html
<h3>This is footer1 section</h3>header2.html
<h3>This is footer2 section</h3>template.html
@extends(layout)
@args String who, String footer
<h1>Hello @who</h1>
@if(footer.equals("footer1")){
@header1();
} else {
@header2();
}https://stackoverflow.com/questions/40154763
复制相似问题