Combining default! and ?number

"Klotz, Leigh" <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <E254B0A7E0268949ABFE5EA97B7D0CF404C0317F@USA7061MS01.na.xerox.net>
In FM 2.3.12, I'd like to assign a variable to be a number which is
either parsed from a string parameter (perhaps from a query string), or
default it to a fixed constant.  I'm not sure if there's a concise
syntax for doing this.

The first code I saw to do this was like this:
 <#assign page>${pageArg!1}</#assign>			[1]

But then all users from then on had to do
    page?number + 1
to refer to it.  Unfortunately, that fails because page is now a number,
and next time, page?number will fail.

So I changed it to this:

<#assign page = pageArg!1 />

This works when pageArg isn't specified, as does this
   page + 1
work properly on every iteration.

However, when pageArg it specified, it turns page into a string, so it
fails again.

So then I tried

<#assign page = pageArg?number!1 />

but that fails because when pageArg is null, pageArg?number fails.

So my next theory was to use #if, which takes me back to

<#assign page><#if
pageArg?is_defined>${pageArg?number}<#else>1</#if></#assign>
but I can see already that would fail beacuse of [1] above.  

That leaves
<#assign page = 1 >
<#if pageArg?is_defined>
  <#assign page = pageArg?number}
</#assign>

This seems a bit cumbersome.

Is there some special syntax I'm missing for defaulting numeric values
from optional strings?!?!

Leigh.



-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
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.