I need to build a cross platform app with multiple windows. So I would like to know how to use html templates in electron.
相关问题
- How can I get a window object from new BrowserWind
- Failed at the electron@1.8.2 postinstall script
- No member named ForceSet
- Export HTMLtable to CSV in electron
- Using electron-usb with electron
相关文章
- Configuring electron-webpack renderer to work with
- Error messages and console logs in Electron?
- Adding Apple in-app purchase to Electron HTML/JS a
- Minimal Example: Opening a window in electron from
- Electron dying without any information, what now?
- Electron without GUI
- Testing Electron application with org.openqa.selen
- How to build the Electron application for the Wind
Based on a similar question and what I've seen, there's no built in html template language in Electron, which is actually great because it allows you to use any other template language.
I'm currently playing with ejs in Electron. Below is my
index.ejs
template file:And below is a section of my
main.js
file where the above template is rendered and loaded onto theBrowserWindow
. Note that I've left out most of the boilerplate code:I'll give some credit to this gist for helping me find the
data:text/html;charset=utf-8
part of the url that can be used to load dynamic content.UPDATE
I'm actually not using this anymore. It's faster to just load the default html and use the native DOM methods. The Electron Quickstart program shows how to do this nicely.
Another option is to do the templating during your build. Here is a simple example using gulp to add nonces to the CSP meta tag and the inline script.
index.html
and in gulfile.js add the following to what you already have and make sure this task is included in your pipeline. You can also just update your current html task with the code below.
This is a very stripped down example. I have a more complete example at https://github.com/NFabrizio/data-entry-electron-app if anyone is interested, though there is still one warning when running the application because one of the packages I am using pulls in react-beautiful-dnd, which adds inline styles but does not currently accept nonces.