Is there a way to embed the HTML from a file into another file? It would be useful for making headers or footers, not needing to paste the same code in every file.
-
1Use php include for that.Vikas Sangle– Vikas Sangle2014-01-18 13:06:53 +00:00Commented Jan 18, 2014 at 13:06
-
What serverside language do u use?Zword– Zword2014-01-18 13:07:25 +00:00Commented Jan 18, 2014 at 13:07
-
@VikasSangle but is there a way to do it without PHP?kyr– kyr2014-01-18 13:07:57 +00:00Commented Jan 18, 2014 at 13:07
-
@kyr You can do it using ajaxZword– Zword2014-01-18 13:08:55 +00:00Commented Jan 18, 2014 at 13:08
-
1Use jquery stackoverflow.com/questions/8988855/…Andrei Zhamoida– Andrei Zhamoida2014-01-18 13:10:06 +00:00Commented Jan 18, 2014 at 13:10
|
Show 1 more comment
4 Answers
You can call them by using jQuery code, Insert it into your webpage head.
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
$(function(){
$("#includedContent").load("/path/to/filename.html");
});
</script>
</head>
And You can show it anywhere in your webpage by inserting
<div id="includedContent"></div>
1 Comment
user2997826
See updated code to call the file in your webpage!
If you don't want to use php, you can combine grunt with a twig generator, you will have the power of Twig (example: includes, layout inheritence, etc.) in your html pages.
Then with grunt build you will generate a dist folder with all the finals html pages.
Example of generator: https://github.com/polem/generator-gruig
1 Comment
Ram
This is the way to go, I use Jade though.