Skip to content

Latest commit

History

40 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

HTML <template> tag script

Create an HTML template and include it everywhere on your website using the <template> tag.

Info

It is not guaranteed that this script works with other frameworks!

Template

This is the HTML template. Everything inside the <head> tag will later be replaced into the <head> tag of the actual page. The same is applied to the <body> tag.

<script> tags are not executed!

<!-- template.html --><!DOCTYPE html><htmllang="en"><!-- Everything enclosed within the <head> tag is inserted into the <head> tag, in the document where the <template> tag is used. --><head><linkrel="stylesheet" href="style.css"></head><!-- Everything enclosed within the <body> tag is inserted at the location, in the document where the <template> tag is used. --><body><p>Hello World!</p><p>This is amazing!</p></body></html>

Index (before replace)

This is the main HTML page where we want to use the <template> tag. Use the src attribute to specify the source path for the HTML template file.

<!-- index.html (before template replace) --><!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>HTML-template</title><!-- include template.js script --><scriptsrc="https://raw.githubusercontent.com/JavaScriptPlayground/html-template-tag/main/template.js" type="module" defer></script></head><body><templatesrc="./template.html"></template></body></html>

Index (after replace)

This is the final version of the HTML page after the templates have been replaced.

<!-- index.html (after template replace) --><!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>HTML-template</title><!-- include script --><scriptsrc="https://raw.githubusercontent.com/JavaScriptPlayground/html-template-tag/main/template.js" type="module" defer></script><linkrel="stylesheet" href="style.css"><!-- This <link> tag was added from the template <head> tag --></head><body><p>Hello World!</p><!-- These two <p> tags were added from the template <body> tag --><p>This is amazing!</p></body></html>

About

Create an HTML template and include it everywhere on your website.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages