A lot of times I find myself writing the following markup:
<if condition='string.IsNullOrEmpty(Model.City) == false'>
$(DisplayCity(city)
</if>
I suggest that if the *condition* attribute has only string type then
spark will generate the code above.
The markup will look something like this:
<if condition='Model.City'>
$(DisplayCity(city)
</if>
which is a lot more elegant.
--
You received this message because you are subscribed to the Google Groups "Spark View Engine Dev" group.
To post to this group, send email to spar...@googlegroups.com.
To unsubscribe from this group, send email to spark-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spark-dev?hl=en.
new (crazy?) idea then, how about:
<if hasvalue="Model.City">
where hasvalue is an extension method that return bool. meaning that
you can put whatever attribute name you like and spark will look for
the extension method.
anther example:
<if hasItems="Model.MyItems"> ||
<if happendToday="Model.Birthday">
> > spark-dev+...@googlegroups.com<spark-dev%2Bunsubscribe@googlegroups .com>
> > Donnhttp://blog.donnfelker.com/- Hide quoted text -
>
> - Show quoted text -
> > > Donnhttp://blog.donnfelker.com/-Hide quoted text -
As for keystrokes - does anyone stumble as much as I do when typing
fluent code due to the shift necessary to type the '=>' ??
> > > > Donnhttp://blog.donnfelker.com/-Hidequoted text -
>
> > > - Show quoted text -- Hide quoted text -
To unsubscribe from this group, send email to spark-dev+...@googlegroups.com.
I did it like this as far as I can recall... (checks for both null
values and empty strings)
Create a file name "_if2.spark" and put in in a shared folder
This should be the content :
<viewdata notnull="Object">
<if condition="notnull != null && notnull!=''" >
<render />
</if>
You can then use it in you spark files like this :
<if2 notnull="Model.City">
$(DisplayCity(city)
</if2>
BTW, a trivial remark: you could also simplify your example code
<if condition='string.IsNullOrEmpty(Model.City) == false'>
to
<if condition='!string.IsNullOrEmpty(Model.City)'>
or
<if condition='(Model.City??"")!=""'>
As for the simplification, I try not to use negative ops, meaning that
instead of "!value" I use the verbose way of "value == false" (but I
never ever "value==true").
the reason for that is the the ! operator something get lost by the
eye/mind (especially in 2AM, 6 hours before release), so in my coding
std I never use ! (but I'm not a zealot about it).