473,416 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How to _not_ strip HTML comments from a HTML template in gin gonic

13 Byte
I'm using Gin Gonic with a HTML template file.

My template file contains (multi line) HTML comments of the kind <!-- my comment goes here-->. I want that the HTML content is preserved in the output which is returned by

Expand|Select|Wrap|Line Numbers
  1. c.HTML(http.StatusOK, "static/templates/mytemplate.html", gin.H{
  2.     "name": "World",
  3. })
where c is a *gin.Context.

Question: How to configure the template engine or c.HTML to not strip the HTML comments from the template?

More Detailed


Expand|Select|Wrap|Line Numbers
  1. /static/templates/mytemplate.html:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html lang="de">
  3. <body>
  4. <!--
  5. these lines are missing in the output
  6. -->
  7. Hello World
  8. </body>
  9. </html>
  10.  
My Handler:


Expand|Select|Wrap|Line Numbers
  1. func NewRouter() *gin.Engine {
  2.     router := gin.Default()
  3.     // ... load templates from file system ...
  4.     router.GET("/foo", fooHandler)
  5.     return router
  6. }
  7. func fooHandler(c *gin.Context) {
  8.     c.HTML(http.StatusOK, "static/templates/mytemplate.html", gin.H{
  9.         "name": "World",
  10.     })
  11. }
Edit I tried to add the comments as constants:

Expand|Select|Wrap|Line Numbers
  1. {{"<!-- my comment goes here -->"}}
But then the tags are escaped as

Expand|Select|Wrap|Line Numbers
  1. &lt;!-- foo --&gt;
Jul 18 '23 #1
0 9129

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: dogu | last post by:
I'm missing something and need a push in the right direction. If I create a php file with the following content, and call it via a browser, it works as expected. <?php echo "hello world"; ?> ...
3
by: Mitchua | last post by:
When I run the well quoted line: my $ascii = HTML::FormatText->new->format(HTML::Parse::parse_html($html)); to remove HTML tags from an html document, it replaces all tables with "". Is there a...
1
by: Hari | last post by:
What is the difference between HTML controls, HTML server controls , ASP.Net controls? Which will give more performance?
38
by: | last post by:
I have a script... ----- <SCRIPT language="JavaScript" type="text/javascript"> <!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this = makeArray.arguments; } ...
9
by: Patient Guy | last post by:
Taking the BODY element as an example, all of its style attributes ('alink', 'vlink', 'background', 'text', etc.) are deprecated in HTML 4.01, a fact noted in the DOM Level 2 HTML specification. ...
3
by: Michal A. Valasek | last post by:
Hello, I want to transform text with HTML markup to plain text. Is there some simple way how to do it? I can surely write my own function, which would simply strip everything with < and >....
2
by: tshad | last post by:
Is there an easy way to strip HTML tags from Text to get just the plain text? I am using a program called FreeTextBox that lets you format Text in a TextBox. It does this by adding HTML tags...
11
by: John Nagle | last post by:
The syntax that browsers understand as HTML comments is much less restrictive than what BeautifulSoup understands. I keep running into sites with formally incorrect HTML comments which are parsed...
14
by: Andy B | last post by:
I need to create a regular expression that will match a 5 digit number, a space and then anything up to but not including the next closing html tag. Here is an example: <startTag>55555 any...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.