简体   繁体   中英

Load HTML Header content from template

I am trying to modify an application so that all of the application php structure runs in separate php files on the server and has nothing to do with the views rendered on the browser. Essentially trying to move more towards a MVC structure. Currently, I have pre-built header and navigation files load into the page like:

<?php include 'tpl/header.html'; ?>

<body>

<?php include 'tpl/navigation.html'; ?>  

I'd like to pull out the php includes so that I am not reliant on them, but I'd still like to use templates for handling this so I don't have to touch each page. I know how to do this for the navigation template using jQuery load, but is it possible for the header template file?

Would handlebars.js be a solution, and if so how?

Thanks for the help!

You can just append html to your head tag with javascript.

var client = new XMLHttpRequest();
client.open('GET', '/header.php');
client.onreadystatechange = function() {
  document.getElementsByTagName('head')[0].innerHTML(client.responseText);
}
client.send();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM