If it stripped HTML comments then it would not be possible to generate output 
that contains wanted comments. Not all generated code is destined to be 
delivered to a renderer. Some might be targeting developers who need to modify 
it manually and for whom comments would be desired, including comments 
containing dynamically generated data.
  

  
Better to use template parser-compatible comments for your use-case, as Jon 
Perryman mentioned, than to limit what can be generated by the package
  
  
  
  
  
  
-Mike
  
  
  

  
>   
> On Dec 31, 2024 at 6:26 AM,  <atilkan (mailto:emrahatil...@gmail.com)>  wrote:
>   
>   
> Yep that would fix the issue. But i am thinking those stripped html comments 
> should not be evaluated. That seems odd to me.
>   
>   
>   
> On Tuesday, 31 December 2024 at 11:20:37 UTC+3 Kurtis Rader wrote:
>   
> >   
> > Argh! I just realized my reference to the comment about the html/template 
> > "HTML" type handling of comments isn't really relevant. The issue is that 
> > the html/template package doesn't inhibit substitution inside a semantic 
> > HTML comment. It does elide comments from the generated output but does 
> > attempt to perform substitutions   within the HTML comment. This doesn't 
> > surprise me but it also   wasn't obvious to me from a quick reading of the 
> > package documentation. Perhaps the documentation would benefit from the 
> > addition of some clarifying text on this point. You have to actually 
> > convert the HTML comment into a literal string. For example, changing
> >   
> >   
> >
> >   
> > >   
> > > <!--  <input value='{{.nonExistingData}}'>  -->
> > >   
> >   
> >
> >     
> >   
> > into
> >   
> >
> >   
> > >   
> > > {{ "<!--  <input value='{{.nonExistingData}}'>  -->" }}
> > >   
> >   
> >   
> >
> >       
> >   
> >   
> > On Mon, Dec 30, 2024 at 11:31 PM Kurtis Rader  <kra...@skepticism.us>  
> > wrote:
> >   
> > >   
> > > You should always include the full error message (and backtrace if 
> > > available) as well as telling   us the relevant version of Go you used to 
> > > compile your program and the particular package you believe is   the 
> > > source of the problem. A minimal reproducible example is also a good idea 
> > > if feasible.  
> > >
> > >   
> > > In this case we're guessing you're using   
> > > https://pkg.go.dev/html/template  but we shouldn't have to guess. Jon 
> > > guessed that the error is from a Javascript interpreter, and not a Go 
> > > stdlib package, because of the lack of context and the wording of the 
> > > partial error message you gave us. I'm guessing the error is from   
> > > src/text/template/exec.go:  
> > >
> > >   
> > > >   
> > > > s.errorf("can't evaluate field %s in type %s", fieldName, typ)
> > > >   
> > >   
> > >
> > >   
> > > Note that html/template delegates the actual substitution to 
> > > text/template.
> > >   
> > >   
> > >
> > >   
> > > The documentation for html/template 
> > > (https://pkg.go.dev/html/temp...@go1.23.4 
> > > (https://pkg.go.dev/html/template@go1.23.4)) explicitly states that the 
> > > HTML type should not contain comments:
> > >   
> > > >   
> > > >   
> > > >
> > > >  HTML encapsulates a known safe HTML document fragment. It should not 
> > > > be used for HTML from a third-party, or HTML with unclosed tags or 
> > > > comments. The outputs of a sound HTML sanitizer and a template escaped 
> > > > by this package are fine for use with HTML.
> > > >
> > > >   
> > > >   
> > >   
> > > Whether that package comment is relevant is unclear since you didn't 
> > > provide enough information for us to do more than make educated guesses.
> > >   
> > >
> > >   
> > > I took the first example program at   
> > > https://pkg.go.dev/html/temp...@go1.23.4 
> > > (https://pkg.go.dev/html/template@go1.23.4)  and inserted your string as 
> > > the first line of the "const tpl = ..." definition. That resulted in this 
> > > runtime failure:
> > >   
> > >
> > >   
> > > >   
> > > > 2024/12/30 23:28:23 template: webpage:2:21: executing "webpage" at  
> > > > <.nonExistingData>: can't evaluate field nonExistingData in type struct 
> > > > { Title string; Items []string }
> > > >   
> > >   
> > >
> > >   
> > > Does that look like the error you're seeing?
> > >   
> > >
> > >     
> > >   
> > >   
> > > On Mon, Dec 30, 2024 at 11:23 AM atilkan  <emraha...@gmail.com>  wrote:
> > >   
> > > >  Hi,
> > > >   
> > > > I am trying to add html comment (yes, they will be removed). I believe 
> > > > it strips the comments after processing the template. If you put 
> > > > non-existing property inside html comments, it throws error.
> > > >  Maybe better to strip comments before processing the template?
> > > >   
> > > >
> > > >   
> > > > `<!--  <input value='{{.nonExistingData}}'>  -->`
> > > >   
> > > >
> > > >   
> > > > I would paste the whole error but you have to search needle in 
> > > > haystack. Basically says  "can't evaluate field   nonExistingData".
> > > >   
> > > >
> > > >   
> > > >  Have a nice day.
> > > >   
> > > >   
> > > >
> > > >
> > > >
> > > >  --
> > > >  You received this message because you are subscribed to the Google 
> > > > Groups "golang-nuts" group.
> > > >  To unsubscribe from this group and stop receiving emails from it, send 
> > > > an email to  golang-nuts...@googlegroups.com.
> > > >  To view this discussion visit   
> > > > https://groups.google.com/d/msgid/golang-nuts/10547051-0324-4257-a81d-33644d92bca5n%40googlegroups.com
> > > >  
> > > > (https://groups.google.com/d/msgid/golang-nuts/10547051-0324-4257-a81d-33644d92bca5n%40googlegroups.com?utm_medium=email&utm_source=footer).
> > > >       
> > >
> > >   
> > >
> > >   --
> > >   
> > >   
> > > Kurtis Rader  
> > > Caretaker of the exceptional canines Junior and Hank
> > >   
> > >   
> > >   
> >   
> >   
> >
> >   
> >
> >   --
> >   
> >   
> > Kurtis Rader  
> > Caretaker of the exceptional canines Junior and Hank
> >   
> >   
> >   
>   
>   
>
>
>
>  --
>  You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
>  To unsubscribe from this group and stop receiving emails from it, send an 
> email to  golang-nuts+unsubscr...@googlegroups.com 
> (mailto:golang-nuts+unsubscr...@googlegroups.com).
>  To view this discussion visit   
> https://groups.google.com/d/msgid/golang-nuts/8eee59b6-538b-4373-8914-6df93355a1e3n%40googlegroups.com
>  
> (https://groups.google.com/d/msgid/golang-nuts/8eee59b6-538b-4373-8914-6df93355a1e3n%40googlegroups.com?utm_medium=email&utm_source=footer).
>              

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/0B677021-9964-4BEC-88F1-3591BBCEC96E%40edison.tech.

Reply via email to