Partial render in HTML/JavaScript

Viewed 47472

I have some HTML files, and each one of them I want to partially render in another HTML file, for example header.html and footer.html in order to observe DRY concept.

HTML files should look like this:

<!--render header.html-->
<div>
    Content
</div>
<!--render footer.html-->

How can I do that?

5 Answers

As others said, it looks like it can't be done with HTML alone. Another way it could be done on the server-side, if you are using Java, is with Thymeleaf.

For example, adding a main menu on every page with <div th:replace="fragments/mainmenu.html"></div> . Then mainmenu.html could just contain a bunch of divs. The fragment doesn't need to be a full HTML page.

Related