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?
答案 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();
}