Re: Multiple layout section override ?

Tony Schwartz <[email protected]> Sat, 09 Mar 2013 08:57:53 -0500
Newsgroups gmane.comp.web.freemarker.user
Organization Iteration Software, LLC
Message-ID <200b23401997bfb1d114242acb1fb3b6@localhost>
I have also done that successfully by setting up a namespace and defining
default macros that can be overridden. 

What I have done is basically this: 


#############
# layout.ftl
#############

<#macro heading>
	DEFAULT HEADING
</#macro>

<#macro content>
	DEFAULT CONTENT
</#macro>

<#macro leftNav>
	DEFAULT LEFT NAV
</#macro>


<#macro doLayout>
    <html>
        <body>
        	<div id="head"><@heading /></div>
        	<div id="leftNav"><@leftNav /></div>
        	<div id="content"><@content /></div>
        </body>
    </html>
</#macro>

#############
# END layout.ftl
#############




#############
# page.ftl
#############
<#import "layout.ftl" as layout />


<#macro heading>
	MY IMPLEMENTATION OF THE HEADING
</#macro>
<#assign heading = heading in layout /><#-- THIS PUSHES THE heading MACRO
INTO THE layout NAMESPACE (OVERRIDING THE ORIGINAL heading MACRO) -->


<#macro content>
	MY IMPLEMENTATION OF THE CONTENT
</#macro>
<#assign content = content in layout /><#-- THIS PUSHES THE content MACRO
INTO THE layout NAMESPACE (OVERRIDING THE ORIGINAL content MACRO) -->


<#-- NOW, CALL THE LAYOUT - the default leftNav is used, but this page
overrides the content and heading sections -->
<@layout.doLayout />

#############
# END page.ftl
#############







On Sat, 9 Mar 2013 20:29:13 +0700, Albert Kam  wrote:  Thanks for the
guide Tony ! 
 Actually i have thought of using the loop variable param,  but i wonder
how to provide the default section content, since what i intended is to
override some sections as needed, and use the default sections if not
'overriden' 
 Example : for page1.ftl, i want to supply the body only, but use the
default left-panel, default header n default footer for page2.ftl, i want
to supply both the body and left-panel, and still use the default header n
default footer 

 On Sat, Mar 9, 2013 at 8:13 PM, Tony Schwartz  wrote:

 Sorry about that previous post! I accidentally sent the email, I just
love
 coding in a bad browser based email client!

 What I have done in the past is this:

 Write your header section here.

 Write your content section here.

 Unsupported section??

 On Sat, 09 Mar 2013 08:09:05 -0500, Tony Schwartz
  wrote:
 > What I have done is this:
 >
 > 
 > 
 > 
 > 
 >
 > 
 >
 >
 >
 >
 > On Wed, 6 Mar 2013 20:46:26 +0700, Albert Kam wrote: I am aware that i
 > can use macros for layouting, for example, a main layout that contains
 > header, left body section, center body section, footer.
 > Based on the examples i have googled, like this one here
 >

http://wendefer.blogspot.com/2007/09/handy-tip-for-layouts-in-freemarker.html
[3]
 > [1], i can use in the main layout for dynamic values for other
templates
 > that use this main layout macro.
 > But in my case, i would like the other templates to be able to
 'override'
 > more than 1 , for example, providing the content of left body section
 -and-
 > center body section (like apache tiles).
 > Is this supported, or maybe is there any other approaches to do this ?
 >
 > --
 > Do not pursue the past. Do not lose yourself in the future.
 > The past no longer is. The future has not yet come.
 > Looking deeply at life as it is in the very here and now,
 > the practitioner dwells in stability and freedom.
 > (Thich Nhat Hanh)
 >
 > Tony Schwartz
 > [email protected] [4]
 >
 >
 > Links:
 > ------
 > [1]
 >

http://wendefer.blogspot.com/2007/09/handy-tip-for-layouts-in-freemarker.html
[5]

 --
 Tony Schwartz
 [email protected] [6]


------------------------------------------------------------------------------
 Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
 Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
 endpoint security space. For insight on selecting the right partner to
 tackle endpoint security challenges, access the full report.
 http://p.sf.net/sfu/symantec-dev2dev [7]
 _______________________________________________
 FreeMarker-user mailing list
 [email protected] [8]
 https://lists.sourceforge.net/lists/listinfo/freemarker-user [9]

 -- 
Do not pursue the past. Do not lose yourself in the future. 
The past no longer is. The future has not yet come. 
Looking deeply at life as it is in the very here and now, 
 the practitioner dwells in stability and freedom.
(Thich Nhat Hanh)  

Tony Schwartz
[email protected]
 

Links:
------
[1] mailto:[email protected]
[2] mailto:[email protected]
[3]
http://wendefer.blogspot.com/2007/09/handy-tip-for-layouts-in-freemarker.html
[4] mailto:[email protected]
[5]
http://wendefer.blogspot.com/2007/09/handy-tip-for-layouts-in-freemarker.html
[6] mailto:[email protected]
[7] http://p.sf.net/sfu/symantec-dev2dev
[8] mailto:[email protected]
[9] https://lists.sourceforge.net/lists/listinfo/freemarker-user

------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev