0

I'm using Express Handlebars as a template engine for node. I know there's an option to add HTML comments with it, but is there a way to add developer comments that won't get printed on the final source ?

This is what I found:

{{! This comment will not be in the output }}
<!-- This comment will be in the output -->

But looking for:

{{! This comment should only be visible in the source file, not in the client side }}

Similar to what can be done in PHP in a view:

<?php
/* Comment here */
?>
Alvaro
  • 40,778
  • 30
  • 164
  • 336
  • You could use a library to minimize the code removing the comments, or use a preprocessor to have them removed. There is also a npm package for this, https://www.npmjs.com/package/gulp-remove-html-comments – Zac Feb 07 '17 at 15:22
  • I'm currently using my own helper to remove them, but just wondering if it is possible somehow else. – Alvaro Feb 07 '17 at 15:45

2 Answers2

5

The correct answer is:

{{!-- This comment won't get printed in this view --}}

https://handlebarsjs.com/guide/#template-comments

Salvioner
  • 303
  • 5
  • 16
Alvaro
  • 40,778
  • 30
  • 164
  • 336
0

I ended up creating my own handlebars helper:

Handlebars.registerHelper('comment', function(whatever) {
  return '';
});

This way I can do:

{{comment 'this field is here to indicate...'}}
<input type="hidden" name="demo" value="4554">
Alvaro
  • 40,778
  • 30
  • 164
  • 336