You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Nathan Bubna (JIRA)" <de...@velocity.apache.org> on 2010/03/28 21:35:27 UTC

[jira] Commented: (VELOCITY-756) New notation for replacing null values with a specified string

    [ https://issues.apache.org/jira/browse/VELOCITY-756?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12850724#action_12850724 ] 

Nathan Bubna commented on VELOCITY-756:
---------------------------------------

As an alternate to #if #else, there is also:

http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DisplayTool.html

which provides $display.alt($foo) and $display.alt($foo, 'n/a') and many other such display control methods.  This is ideally where "extra" features like this go.   The tool approach has several advantages:

- keeps VTL syntax simple and contained (feature creep has its costs)
- provides API that is easy to extend and enhance
- typically provides much more clear and user-friendly API

Unless the $?foo syntax were to become something frequently requested (which it has never been), i don't see us working to adopt it anytime soon, for the reason of keeping things simple.

> New notation for replacing null values with a specified string
> --------------------------------------------------------------
>
>                 Key: VELOCITY-756
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-756
>             Project: Velocity
>          Issue Type: New Feature
>          Components: Engine
>            Reporter: Ludwig Magnusson
>            Priority: Minor
>
> If I have a variable $foo and it is null, I have the option of using the silent notation $!foo for not writing it. But often when genrating HTML pages I want to express that the values is missing, e.g. by a "-". That means that I have to write my code like this:
> #if($foo)
>   $foo
> #else
>   -
> #end
> Wouldn't it be great if there were a new option like $?foo (or whatever chararter would be suitable instead of "?") that would print the variable $foo if it was not null and otherwise print a predefined character like "-".
> /Ludwig

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org