I want to include a single html header file header.html
in each rest of the files in the folder while using php localhost we use <?php include 'header.php'; ?>
just change the extension and use it everywhere but now I'm using the * golang and I don't know how to include the header.html
file in each of the html file. I will done this for once write individually because there two files but if there are 50 files of html then its very time taken to write the code individually. How to include a single file of html header in the rest of the html files in folder?
The code I'm using is
html file
<body>
<header>{{template "bootstrap_header.html"}}</header>
<h3>Login Here</h3>
<input type="text" id="email" name="email" value="" placeholder="enter your email here">
<input type="text" id="password" name="password" value="" placeholder="enter your password here">
<button id="button_first">Click it for Login</button>
<script>
$(document).ready(function(){
$('button').on('click', function(e){
var email = $('#email').val()
var password = $('#password').val()
$.ajax({
url:"/api/v2/login",
type:"POST",
data: {'email':email, "password":password},
success: function(results) {
console.log(results)
if(results.response.message === "Success"){
console.log("hello")
alert(results.response.message);
function setCookie(cname, cvalue, exdays) {
document.cookie = cname + "=" + cvalue + ";path=/";
}
setCookie("X-Test-Header", results.response.total_record)
document.location.href = "/api/v1/customer?Number="+results.response.data[0]._id;
}
if(results.response.message === "Failure"){
console.log("hello")
alert(results.response.data);
}
}
});
});
});
</script>
</body>
This page will redirect me at the given url document.location.href = "/api/v1/customer?Number="+results.response.data[0]._id;
Go code
t, err := template.ParseFiles("buttons.html", "bootstrap_header.html")
if err != nil {
panic(err)
}
err = t.ExecuteTemplate(os.Stdout, "buttons.html", nil)
if err != nil {
panic(err)
}
Gives me output as in terminal
Both file code in the terminal
Expected output is to display it in the browser