27

I'm trying to generate a comment on a single line at the end of an HTML file:

<!-- generated by SERVER1 -->

I have tried

/
  generated by #{@server_name}

But this outputs it over 3 lines -

<!-- 
    generated by SERVER1 
-->

I've tried

/ generated by #{@server_name}

But that doesn't evaluate the @server_name var -

<!-- generated by #{@server_name} -->

Any ideas?

Flip
  • 6,233
  • 7
  • 46
  • 75
Marklar
  • 1,056
  • 2
  • 13
  • 31
  • 2
    It's still an open issue: https://github.com/nex3/haml/issues/313. I think you're stuck with the multiline comment for now, even though nex3 says single line interpolation should work. – kafuchau Apr 12 '12 at 13:40
  • ahh lameo. If you would like to add your comment as an answer I'll give you a tick. Cheers – Marklar Apr 12 '12 at 13:49
  • 1
    This is now fixed in Haml master, https://github.com/haml/haml/commit/dd530babee5b894f5433db59d2e7517b3d9a9c50 It should be in Haml 4.1 (or 5 – https://github.com/haml/haml/issues/761). – matt Apr 14 '14 at 02:14

2 Answers2

24

Just as you can drop back to raw HTML output when you want, so you can drop in raw HTML comments, even with interpolation.

This template:

- @foo = 42
#test1
  /
    Hello #{@foo}
#test2
  <!-- Hello #{@foo} -->

Produces this output:

<div id='test1'>
  <!--
    Hello 42
  -->
</div>
<div id='test2'>
  <!-- Hello 42 -->
</div>

Tested with Haml v3.1.4 (Separated Sally)

Phrogz
  • 296,393
  • 112
  • 651
  • 745
3

It's still an open issue: github.com/haml/haml/issues/313. I think you're stuck with the multiline comment for now, even though nex3 says single line interpolation should work.

Dorian
  • 22,759
  • 8
  • 120
  • 116
kafuchau
  • 5,573
  • 7
  • 33
  • 38