Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use a <template> tag for header and footer components #84

Open
thescientist13 opened this issue Mar 10, 2024 · 1 comment · May be fixed by #85
Open

use a <template> tag for header and footer components #84

thescientist13 opened this issue Mar 10, 2024 · 1 comment · May be fixed by #85
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@thescientist13
Copy link
Member

thescientist13 commented Mar 10, 2024

Overview

Although we are just using Light DOM for the header and footer, e.g.

export default class HeaderComponent extends HTMLElement {
  // run some code to set HTML when the component is ready
  connectedCallback() {
    this.innerHTML = this.getTemplate();
  }

  // create templates that interpolate variables and HTML!
  getTemplate() {
    return `
      <!-- a bunch of HTML -->
    `;
  }
}

customElements.define('app-header', HeaderComponent);

It would likely be a bit more idiomatic to use a <template> tag

const template = document.createElement('template');

template.innerHTML = `
  <!-- a bunch of HTML -->
`;

export default class HeaderComponent extends HTMLElement {
  // run some code to set HTML when the component is ready
  connectedCallback() {
    this.innerHTML = template.content.cloneNode(true); // or something similar
  }
}

customElements.define('app-header', HeaderComponent);

Would also want to make sure this change is reflected in the Greenwood getting started guide
https://www.greenwoodjs.io/getting-started/branding/#templating

@thescientist13 thescientist13 added enhancement New feature or request good first issue Good for newcomers labels Mar 10, 2024
@srpcoder
Copy link

Hi there,
Changes were made. Kindly review the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
2 participants