Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Optional properties and clean markup

A.D
A.D
Vote:
 

Hello,

Any recommendations on the best way to generate clean markup when you have optional properties in a block or page?

For example, I might have something like this:

@Html.PropertyFor(x => x.Intro)

If that property isn't populated, we end up with an empty

tag.

I've done something like this:

 @if (@Model.Intro != null) //or maybe check for isnunllorwhitespace?
{

@Html.PropertyFor(x => x.Intro)

}

That can get repetetive, are there any common ways to tackle this issue?

Thanks,

#113934
Dec 02, 2014 1:48
Vote:
 

You could create your own DisplayTemplates that will be used instead of the default ones. See this post for more information: http://joelabrahamsson.com/how-episervers-html-helper-propertyfor-works/.

Hope this helps.

Frederik

#113935
Dec 02, 2014 3:14
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.