Как включить отдельный заголовочный файл в каждый html-файл, содержащийся в папке? - PullRequest
0 голосов
/ 12 мая 2018

Я хочу включить один заголовочный файл 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

Ожидается вывод его в браузере

1 Ответ

0 голосов
/ 12 мая 2018

Вы можете использовать атрибуты 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 include

...