Creating attributes with @html.raw
Opened this issue · 3 comments
Hi, I want to make some attribute according to condition.
@{ var homepageClass = model.homepage ? ' class="homepage"' : ""; }
<body@html.raw(homepageClass)>
</body>
Generated code:
<body class="homepage">
</body class="homepage">
¿Is this an expected behavior?
This is definitely a bug, but there is a workaround. The problem is that vash is interpreting the html tag name as, literally, body@html.raw(homepageClass)
.
Workaround: Put a space in there! => <body @html.raw(homepageClass)>
Of course, you'll need to change your ternary to not include the space as well.
Found another bug related: <body @model.what class=""></body>
fails to compile due to the parser not bailing on the space between .what
and class
. Workaround: enclose model.what in parens: <body @(model.what) class=""></body>
Thank you @kirbysayshi for answering, long time but better than never 😄 I used this option <body @html.raw(homepageClass)>
for working around. I really expect this gets fixed soon :)