| title | Example of Standard Web Component |
|---|---|
| star_wars | Attack of the Clones |
{{< star-wars >}}
| baseURL = "https://example.com" | |
| languageCode = "en-us" | |
| title = "Example of Standard Web Component" |
| title | Example of Standard Web Component |
|---|---|
| star_wars | Attack of the Clones |
{{< star-wars >}}
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| {{ partial "metadata.html" . }} | |
| {{ partial "css.html" . }} | |
| {{ partial "scripts.html" . }} | |
| </head> | |
| <body> | |
| {{ partial "templates.html" . }} | |
| {{ .Content }} | |
| </body> | |
| </html> |
| <template id="star-wars-tmpl"> | |
| <h1>{{ .Params.star_wars }}</h1> | |
| <p class="obiwan"></p> | |
| <p class="grievous"></p> | |
| </template> | |
| <script | |
| type="application/javascript" | |
| src="/js/components/star-wars.js"> | |
| </script> |
| <!-- Include CSS here --> |
| <meta charset="utf-8" /> | |
| <title>Hugo and Standard Web Components</title> |
| <script | |
| type="application/javascript" | |
| src="https://code.jquery.com/jquery-3.6.0.min.js" | |
| integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" | |
| crossorigin="anonymous"> | |
| </script> | |
| <script | |
| type="application/javascript" | |
| src="/js/components/index.js"> | |
| </script> |
| {{ partial "components/star-wars.html" . }} | |
| <!-- include other templates here --> |
| <star-wars /> |
| window.BaseWebComponent = { | |
| extends({ tag, template, render }) { | |
| customElements.define(tag, class extends HTMLElement { | |
| connectedCallback() { | |
| const fragment = document.getElementById(template) | |
| const node = document.importNode(fragment.content, true) | |
| const instance = $('<div/>') | |
| instance.append(node) | |
| render(instance) | |
| $(this).append(instance) | |
| } | |
| }) | |
| } | |
| } |
| BaseWebComponent.extends({ | |
| tag: 'star-wars', | |
| template: 'star-wars-tmpl', | |
| render(instance) { | |
| instance.find('.obiwan').text('hello there') | |
| instance.find('.grievous').text('general kenobi') | |
| } | |
| }) |