Re: Is there a directive like <#continue> and <#exit>?

"Newman, John W" <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <D688C4D318A63D4290AA94A33E06F7D20182B7798E@msxmbxnsprd14.acct.upmchs.net>
I've written a few templates where I wanted continue, but not having it isn't a killer.

[#list collection as element]
	[#if element.ignore]
		[#continue /]  [#-- skip over this item and run next item in loop --]
	[/#if]
	[#include "element.ftl" /]
[/#list]

w/o continue

[#list collection as element]
	[#if ! element.ignore]
		[#include "element.ftl" /]
	[/#if]
[/#if]

That's a pretty silly example, in practice continue can actually make the loop body cleaner and shorter. 


And I fully agree with the author that an [#abort /] (or [#exit /], etc) directive that just quietly quits the template IS necessary.
[#ftl]
[#if item?exists]
   1000 lines indented once due to being inside if
[/#if]

w/ abort
[#ftl]
[#if ! item?exists]
	[#abort /]
[#/if]
1000 lines not indented once, simple sanity check at top.


Also we'd like to have sanity checks like this in our header page..
[#if ! backingBean.loggedInUser?exists]
	[#abort /]  [#-- maybe someone found a security hole.. don't show content --]
[/#if]

I know there were a few other scenarios where we wanted an abort.. but I can't recall right now.


-----Original Message-----
From: Attila Szegedi [mailto:[email protected]] 
Sent: Thursday, February 12, 2009 2:55 AM
To: FreeMarker-user
Subject: Re: [FreeMarker-user] Is there a directive like <#continue> and <#exit>?


On 2009.02.12., at 8:14, Jiming Liu wrote:

> Hi,
>
> Sometimes, I need break the parse of file by using <#exit> like  
> directive. Freemarker has <#stop>, but the document says <#stop> is  
> to process exception. Is there any other way I can exit a parsing  
> process?

Parsing, or rendering?

Well, you can put the full body of your template in a macro, and then  
use <#return/> in it. Of course, that doesn't exit from multiple  
levels of macros, includes, etc. For that functionality, <#stop/> is  
the way to go - you just need to make sure to catch and ignore the  
exception on the top-level (again, you might be able to use  
FreeMarker's <#attempt> ... <#recover> on top level for that).

> And I also find that add a directive <#continue> would be very  
> helpful.

What would it do? Continue with next iteration of a loop?

Attila.

> Great thanks
>
> Jiming


------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.