[英]Rythm Template Inheritance
我們有一個公共的頁眉/頁腳模板作為父模板,我們將重復使用100個子模板。 擴展指令不支持此功能...
當我瀏覽Rythm文檔時,我找到了一種通過include / invoke指令實現此目的的方法,但是include / invoke指令的主要目的是調用公共函數。 Extends指令以相反的方式進行支持,方法是將主模板內容與render指令一起作為父模板,而將header / footer模板作為子模板,但實時用例則完全不同
我的理解對嗎? 有辦法解決我的問題嗎?
編輯:
我已經像下面的代碼來實現它:
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>
我所做的是借助於包含/調用方法調用的幫助,我得到了結果,但是當我使用擴展時,它不起作用。 如果有可能,您可以使用擴展解決我的問題嗎?
要使用@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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.