When saving a Razor Mediator Template it fails anytime that I have an if statement with unbalanced html tags in side of it.
@if (Fields.subtitle != null)
{
<div class="subtitleColor">
}
else
{
<div class="no-color">
}
...
I've read through the razor mediator documentation and it appears to be preferred to use the ternary operator:
<div class="@(Fields.subtitle != null ? "subtitle-color" : "no-color")">
However I can think of some situations where we might want to add html blocks inside of this (and they could get quite long/complex). The solutions I have found look like this:
@(Fields.releaseMediaTitle == null ? "<div class=\"subtitleColor\"><a href=\"http://www.example.com\">" : "<div class=\"no-color\">")
or this:
@(Fields.releaseMediaTitle == null ?
"<div class=\"col-sm-12\"><a href=\"http://www.example.com\">"
:
"<div class=\"col-sm-8\">"
)
However, this it a bit tough to read (especially if it grows to be much larger) and really I'm just making a if/else statement disguised as a ternary statement. It would be nice to simply code this as an if/else statement instead. The obvious solution is to make two large if/else blocks which contain all of the repeated code, but this solution suffers from a lot of duplication. Is there a better way to accomplish this?