2016-10-20 175 views
0

我们有一个共同的页眉/页脚模板作为父模板,我们将重复使用100个子模板。 Extends指令不支持这...Rythm模板继承

当我翻阅Rythm文档时,我找到了一种通过include/invoke指令实现这一点的方法,但include/invoke指令的主要目的是调用常用函数。 Extends指令以相反的方式支持,将主模板内容与渲染指令一起作为父模板和页眉/页脚模板作为子模板,但实时用例完全不同

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

编辑:

我已经编写象下面这样实现它:

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方法invocati的帮助下我已经得到了结果,但是当我使用延伸它不起作用。如果有可能你可以解决我的情况使用扩展?

+0

我不明白,为什么你说的扩展指令,不支持这一点。 '@ extend'指令旨在实现模板布局。请参阅http://fiddle.rythmengine.org/#/editor/886606b3a7034088b991855bef8f89da –

+0

我已经添加了示例代码,我在我的应用程序中使用。请考虑一下。 – suresh

回答

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(); 
} 
+0

是的,我已经尝试过 – suresh

+0

你可能想upvote绿色答案 –