php - 如何在文件夹包含的每个HTML文件中包含单独的头文件?

标签 php html go include

我想在使用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/

相关文章:

php - Laravel [5.2.21] 自定义 Auth Guard 不持久

phpmyadmin - 如何增加 phpmyadmin 的内存大小

php - 向数据库发送 0 个值

javascript - 为什么 jquery.ui.all.css 用于选项卡

go - 在指定路径中创建新文件

javascript - 在 php 页面之间传递 javascript 值

javascript - 如何显示来自 li-objects 的特定 div?

html - 指定初始大小的流体图像

regex - 替换字符串中除最后 4 个字符外的所有字符

go - 随机数随时间包