Rythm Template Inheritance

时间:2016-10-20 12:39:32

标签: java template-engine rythm

We have a common header/footer template as parent template which we will reuse for 100 of sub templates. Extends directive is not supporting this...

When i go over the Rythm documentation, i found a way to achieve this by include/invoke directives but the primary purpose of include/invoke directive is to invoke common function. Extends directive is supporting in a reverse way by putting main template content with a render directive as a parent and header/footer template as a subtemplate but the realtime usecase is totally different

Is that my understanding right? Is there a way to solve my problem?

Edited:

I have coded like below to achieve it:

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>

What i have done is with the help of include/invoke method invocation i have got the result but when i use extends it doesn't work. If it is possible can u solve my case using extends?

1 个答案:

答案 0 :(得分:2)

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