【问题标题】:Rythm Template Inheritance节奏模板继承
【发布时间】:2016-10-20 12:39:31
【问题描述】:

我们有一个通用的页眉/页脚模板作为父模板,我们将为 100 个子模板重复使用。扩展指令不支持这个...

当我查看 Rythm 文档时,我找到了一种通过包含/调用指令来实现此目的的方法,但包含/调用指令的主要目的是调用通用函数。 Extends 指令以相反的方式支持,将带有渲染指令的主模板内容作为父模板,将页眉/页脚模板作为子模板,但实时用例完全不同

我的理解对吗?有没有办法解决我的问题?

已编辑:

我编写了如下代码来实现它:

页脚.html

@def header1() {
    <h3>This is footer1 section</h3>
}

@def header2() {
    <h3>This is footer2 section</h3>
}

模板1.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>

我所做的是在包含/调用方法调用的帮助下,我得到了结果,但是当我使用扩展时它不起作用。如果可以的话,你能用extends解决我的问题吗?

【问题讨论】:

  • 我不明白你为什么说扩展指令不支持它。 @extends 指令旨在实现模板布局。请参考fiddle.rythmengine.org/#/editor/…
  • 我添加了我在我的应用程序中使用的示例代码。请仔细查看。

标签: java template-engine rythm


【解决方案1】:

要使用@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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 2011-04-17
    • 2013-12-13
    • 2010-10-04
    • 2011-04-08
    • 2016-01-19
    • 2016-11-14
    • 2011-02-27
    相关资源
    最近更新 更多