I am on php and use includes for the navbar and sidebar.
Problem with that is that the design view UI is not available, and coding dynamic menu items requires a workaraound (via a temporary page and then copy/ past)
For the creation of a custom element, all that is required is to place the html code as a template inside the following construction. Notice the backticks.
class ELEMENT extends HTMLElement {
constructor() {
super()
this.innerHTML = `
HTML CODE GOES HERE
`
}
}
window.customElements.define('CUSTOM-ELEMENT', ELEMENT)
Change the capitalized words to suit, making sure that the used element is hyphenated.
In the same JavaScript document, you can place as many custom elements as you wish, requiring just the one JS link for each page.
The great part: there is no need for a PHP extension if no other PHP code is used in the document.
Edit: I have created a short tutorial (if needed).
@elphin how did you create the include?
Did you use the Wappler’s move to include functionality or did you create the include manually by hand (in code view)?
Thanks Ben for your detailed reply.
Looks like this can work but also a little complicated. And I'm not sure if I can edit the code easily with sources from the page the include is used in (sever connects for example), as normal includes allow me to as I just learned.
Where would Custom elements be superior/better suited over SSI includes?
Ah, I see, that was the problem. I now did it the Wappler way and I can use all the resources from the original/parent page!
The fact that this include will be used on many other pages does not really matter I gues? It's just so that the sources from the original page are available when I want to edit the include file right?
You are right, custom elements do not currently fit in with Wappler in the same way that Wappler handles an include. This makes it harder for a non-coder.
As @George states in another post, Wappler is considering the ability to create custom elements and custom App Connect components (two related objects) in a more natural editor. Fingers crossed.
For plain HTML websites with no server-side code, this is the only solution.
Executes in the browser instead of a journey to the server and back.
More flexibility. What I have shown is a very simple example.
Imagine this custom element <live-timer id="elem"> that keeps the current time as in
Admittedly, this would make an excellent App Connect component rather than just a custom element. But as said, the two are related; one is a general version, the other has been Wapplerised.