Fwd: template inheritance for freemarker

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: template inheritance for freemarker

badqiu
hi, 

Coming from a background in Django, I often use "template inheritance", where multiple templates inherit from a common base.
so, I extension freemarker to support template inheritance.

Overview:

base.ftl
<html>  
   
<head>  
        <@block name="head">base_head_content</@block>  
   
</head>  
   
<body>  
        <@block name="body">base_body_content</@block>  
   
</body>  
</html>  
child.ftl
<@override name="body">  
   
<div class='content'>  
        Powered By rapid-framework  
   
</div>  
</@override>  
<@extends name="base.flt"/>
child.ftl output
<html>  
   
<head>  
        base_head_content  
   
</head>  
   
<body>  
       
<div class='content'>  
            Powered By rapid-framework  
       
</div>  
   
</body>  
</html>  
Configuration
configuration.setSharedVariable("block", new BlockDirective());  
configuration
.setSharedVariable("override", new OverrideDirective());  
configuration
.setSharedVariable("extends", new ExtendsDirective());

source code:





------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: template inheritance for freemarker

Guo Du-4
On Wed, Jul 21, 2010 at 5:32 AM, badqiu <[hidden email]> wrote:
> Coming from a background in Django, I often use "template inheritance",
> where multiple templates inherit from a common base.
> so, I extension freemarker to support template inheritance.

I personally use macro to achieve similar requirement without tweak
configuration:


master.ftl====================
<#macro page_head>
        <title>master title</title>
</#macro>
<#macro page_body>
        master body
</#macro>
<#macro page_html>
        <html>
          <head>
          <@page_head/>
          </head>
          <body>
          <@page_body/>
          </body>
        </html>
</#macro>


child.ftl====================
<#include "master">
<#macro page_head>
        <title>child title override where necessary</title>
</#macro>
<@page_html/>


-Guo

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel