Skip to content

Commit ed19dd9

Browse files
authored
Merge pull request #385 from odsantos/update-en-template-element
Update "Template element" article
2 parents c60e75d + c98b1e1 commit ed19dd9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

8-web-components/4-template-element/article.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
# Template element
33

4-
A built-in `<template>` element serves as a storage for markup. The browser ignores it contents, only checks for syntax validity, but we can access and use it in JavaScript, to create other elements.
4+
A built-in `<template>` element serves as a storage for HTML markup templates. The browser ignores its contents, only checks for syntax validity, but we can access and use it in JavaScript, to create other elements.
55

6-
In theory, we could create any invisible element somewhere in HTML for markup storage purposes. What's special about `<template>`?
6+
In theory, we could create any invisible element somewhere in HTML for HTML markup storage purposes. What's special about `<template>`?
77

88
First, its content can be any valid HTML, even if it normally requires a proper enclosing tag.
99

@@ -31,9 +31,9 @@ We can put styles and scripts into `<template>` as well:
3131
</template>
3232
```
3333

34-
The browser considers `<template>` content "out of the document", so the style is not applied, scripts are executed, `<video autoplay>` is not run, etc.
34+
The browser considers `<template>` content "out of the document": styles are not applied, scripts are not executed, `<video autoplay>` is not run, etc.
3535

36-
The content becomes live (the script executes) when we insert it.
36+
The content becomes live (styles apply, scripts run etc) when we insert it into the document.
3737

3838
## Inserting template
3939

@@ -87,7 +87,7 @@ Let's rewrite a Shadow DOM example from the previous chapter using `<template>`:
8787
</script>
8888
```
8989

90-
In the line `(*)` when we clone and insert `tmpl.content`, its children (`<style>`, `<p>`) are inserted instead.
90+
In the line `(*)` when we clone and insert `tmpl.content`, as its `DocumentFragment`, its children (`<style>`, `<p>`) are inserted instead.
9191

9292
They form the shadow DOM:
9393

@@ -109,8 +109,8 @@ To summarize:
109109

110110
The `<template>` tag is quite unique, because:
111111

112-
- The browser checks the syntax inside it (as opposed to using a template string inside a script).
113-
- ...But still allows to use any top-level HTML tags, even those that don't make sense without proper wrappers (e.g. `<tr>`).
112+
- The browser checks HTML syntax inside it (as opposed to using a template string inside a script).
113+
- ...But still allows use of any top-level HTML tags, even those that don't make sense without proper wrappers (e.g. `<tr>`).
114114
- The content becomes interactive: scripts run, `<video autoplay>` plays etc, when inserted into the document.
115115

116-
The `<template>` tag does not feature any sophisticated iteration mechanisms, data binding or variable substitutions, making it less powerful than frameworks. But we can build those on top of it.
116+
The `<template>` element does not feature any iteration mechanisms, data binding or variable substitutions, but we can implement those on top of it.

0 commit comments

Comments
 (0)