kirbysayshi / vash

Vash, the 60 billion double-dollar template-maker. Razor syntax, for JavaScript templates
Other
524 stars 60 forks source link

Creating attributes with @html.raw #112

Open sant123 opened 7 years ago

sant123 commented 7 years ago

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?

kirbysayshi commented 7 years ago

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.

kirbysayshi commented 7 years ago

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>

sant123 commented 7 years ago

Thank you @kirbysayshi for answering, long time but better than never :smile: I used this option <body @html.raw(homepageClass)> for working around. I really expect this gets fixed soon :)