Producing Single-Line Comments with Haml?

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?

4

2 Answers

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)

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest