Re: Combining default! and ?number
"Jonathan Revusky" <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Maybe this would work for you: (pageArg?number)!1 On Tue, Apr 29, 2008 at 1:11 AM, Klotz, Leigh <[email protected]> wrote: > 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 > _______________________________________________ > FreeMarker-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/freemarker-user > ------------------------------------------------------------------------- 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