codepb/jquery-template

add flag to use template.contents() instead of template.children() to include comments

Opened this issue · 1 comments

The change here is fairly straightforward, but wanted to get your thoughts before submitting a pull request. I'm creating templates in standalone html files, pretty much like:

<!-- filename.html -->
<h1>Something something something</h1>

My intention was for the filename comment to get rendered so that anyone looking at the rendered webpage later that wanted to change some copy could go find that file easily and make their edits. After tracing through the plugin, it looks like the comments disappear on line 212 of jquery.loadTemplate.js

var $templateHtml = template.children().clone(true);

By replacing children() with contents() we get all of the nodes (including the comments, yay!)... but that only works with HTML comments. If you're using

//javascript comments

or your template was declared on the same page, it would just render the plain text of your comment.

So what I'd like to implement is an extra option to use contents instead of children (the default would be false). Something like "renderComments" or "useContents" or "renderAllNodes" which would default to false. Flip it on if you know what you're doing, but otherwise everything would work exactly the same.

What do you think?

yes, I think this should be fine. I don't know if it would have any side effects, so would need to be tested to make sure.