Call header and footer without mixing php in html

Asked

Viewed 965 times

0

How to not mix PHP in HTML?

I have a file header.html - i want that file to be shown on every page of my site. How do I do this without renaming the header.html for header.php and give a:

<?php

include "header.php"

?> 
  • Wow friend eh only leave with header.html even, since there is no php code inside the header... And the pages that will receive this include have to be . php

  • <?php include "header.html"; ?>

  • Do you want to use PHP to include an HTML file, or do you not want PHP for anything? See if this other question here clarifies your doubt.

  • I don’t want to mix php in my html that I don’t want to have a header.php I want a header,html, but I want to call Reader in my index without giving a include header.php, got it ?

1 answer

0

You can do it using javascript

Imagining that your index.html be it so.

Create in the same directory as index.html a file called header.html and footer.html.

Tested on the server vertrigo.

You will not be able to run this code by clicking directness about the archive index.html

<html>
<head>
<title>load html</title>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script> 
$(function(){
  console.log('init');
  $("#header").load("header.html"); 
  $("#footer").load("footer.html"); 
});
</script> 
</head>
<body>
<div id="header" style="text-align:center;"></div>
<content>
    <section>
        <div class="form-group">
            <label>label</label>
	   <input type="text" />
	</div>
    </section>
</content>
<div id="footer" style="text-align:center;"></div>
</body>
</html>

header.html

footer.html

  • Have some other method without using js ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.