gin-gonic / gin

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
https://gin-gonic.com/
MIT License
79.39k stars 8.04k forks source link

Gin do not support javascript ? #3869

Open devgis opened 9 months ago

devgis commented 9 months ago

Description

If I added javascript into the html template file ,It will not appear in the view ?

How to reproduce

{{define "posts/index.html"}}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>posts/index</title>
</head>
<body>

<h1>{{.title}}</h1>
<h3>{{.MyParam}}</h3>
<h3>{{.JsonParam}}</h3>
<h3>{{.JsonParam.a}}</h3>
<div id="demo"></div>

{{/*    
    <script>
        var x;
        var txt="";
        var person={{.JsonParam}}
        for (x in person){
            txt=txt + person[x].a;
        }
        document.getElementById("demo").innerHTML=txt;
        </script>
    */}}
</body>

</html>
{{end}}

Expectations

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>posts/index</title>
</head>
<body>

<h1>title</h1>
<h3>xxx</h3>
<h3>yyy</h3>
<h3>zzz</h3>
<div id="demo"></div>
      <script>
          var x;
          var txt="";
          var person={x:1,y:2}
          for (x in person){
              txt=txt + person[x].a;
          }
          document.getElementById("demo").innerHTML=txt;
          </script>

</body>

</html>

Actual result

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>posts/index</title>
</head>
<body>

<h1>title</h1>
<h3>xxx</h3>
<h3>yyy</h3>
<h3>zzz</h3>
<div id="demo"></div>
</body>
</html>

If I added javascript into the html template file ,It will not appear in the view ?

Environment

RedCrazyGhost commented 9 months ago

Please add the expected effect and actual effect, at present, I can't judge your needs by looking at the issue.

devgis commented 9 months ago

Please add the expected effect and actual effect, at present, I can't judge your needs by looking at the issue.

Hi,Edited . As you can see in the Actual result the "script" codes were missed.

RedCrazyGhost commented 9 months ago

HTML natively supports Githubissues.

  • Githubissues is a development platform for aggregating issues.