我想在使用php localhost时在文件夹的其余每个文件中都包含一个html头文件header.html
,我们使用<?php include 'header.php'; ?>
只是更改扩展名并在所有地方使用它,但是现在我使用的是* golang ,知道如何在每个html文件中包括header.html
文件。我将一次完成此操作,因为有两个文件,但是如果有50个html文件,则需要花费很长时间单独编写代码。如何在文件夹中的其余html文件中包括单个html header 文件?
我正在使用的代码是
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
Expected output is to display it in the browser
最佳答案
您可以使用HTML 5属性 w3-include-html
content.html
<ahref="howto_google_maps.asp">Google Maps</a><br>
<ahref="howto_css_animate_buttons.asp">Animated Buttons</a><br>
<ahref="howto_css_modals.asp">Modal Boxes</a><br>
<ahref="howto_js_animate.asp">Animations</a><br>
<ahref="howto_js_progressbar.asp">Progress Bars</a><br>
<ahref="howto_css_dropdown.asp">Hover Dropdowns</a><br>
<ahref="howto_js_dropdown.asp">Click Dropdowns</a><br>
<ahref="howto_css_table_responsive.asp">Responsive Tables</a><br>
<div w3-include-html="h1.html"></div>
<div w3-include-html="content.html"></div>
这项工作就像php 和
关于php - 如何在文件夹包含的每个HTML文件中包含单独的头文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50302838/