douzhicui2209 2018-05-12 04:26
浏览 94

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

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

  • 写回答

1条回答 默认 最新

  • douji9816 2018-05-12 08:08
    关注

    You Can Use Html 5 Attributes 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>

    This is work like a php include

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题