How to include partials



I would like to ask you how to include partial HTML code.

For example, I have a HTML code which is repeating, so I want to include it in files, without copying it to every file.


There are a few ways. The answer would depend on what the code is for.

My first question is about how this is related to Electron. Electron can work with multiple pages, but it’s primarily used for single-page apps (SPAs), which use a single HTML page and have a Javascript application that manipulates the DOM. Please elaborate a little more on what you intend to achieve, and we can offer suggestions on which directions to move.


For example I want include HTML inside and footer of app, but you can write all ways and explain which way is good for. :slight_smile:


No. I hang around this forum for fun because I like stretching my brain and answering questions. I’m not going to give you a course on all methods of transclusions, frames, and DOM manipulation. I don’t have the time or motivation.


haha :smiley: so for example the most basic way


Are you using a view framework for your app, or are you using raw DOM manipulation?


I don’t know what is view framework, so probably DOM manipulation :smiley:


View frameworks are JavaScript libraries that help app developers to easily manipulate elements in the DOM without having to go through the often tedious process of setting up all of those elements individually. View frameworks include some lightweight, view-only frameworks like Vue and Etch, but also larger and smarter fixtures such as Angular and React.

Here’s a tutorial on how to add elements to the DOM with JavaScript. You can write a function that contains everything you want your footer to say, and then insert it into the page.