Я хочу включить один заголовочный файл html header.html
в остальные файлы в папке, при использовании php localhost мы используем <?php include 'header.php'; ?>
, просто измените расширение и используйте его везде, но теперь я использую * golang и я не знаю, как включить файл header.html
в каждый html-файл.Я сделаю это один раз, чтобы написать индивидуально, потому что есть два файла, но если есть 50 файлов HTML, то самое время, чтобы написать код по отдельности.Как включить один файл HTML-заголовка в остальные HTML-файлы в папке?
Я использую код
html файл
<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>
Эта страница перенаправит меня по указанному URL document.location.href = "/api/v1/customer?Number="+results.response.data[0]._id;
Перейти код
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)
}
Дает вывод, как в терминале
Both file code in the terminal
Ожидается вывод его в браузере