Skip to content

Commit ef5e2dd

Browse files
fine traduzione articolo
1 parent 2890176 commit ef5e2dd

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33

44
Un elemento `<template>` built-in funziona come uno storage per i templates del markup HTML. Il browser ne ignora il contenuto, controllando solamente la validità della sintassi, ma possiamo accedervi ed usarli via JavaScript, per creare altri elementi.
55

6-
In teoria, possiamo creare qualunque elemento invisibile in qualunque punto dell'HTML, allo scopo di salvare del markup HTML. Cosa possiamo dire su `<template>`?
6+
In teoria, possiamo creare qualunque elemento invisibile in qualunque punto dell'HTML, al solo scopo di salvare del markup HTML. Cosa possiamo dire su `<template>`?
77

8-
First, its content can be any valid HTML, even if it normally requires a proper enclosing tag.
8+
Prima di tutto il contenuto può essere un qaualunque tipo di HTML valido, anche se, normalmente richiede un tag di inclusione appropriato.
99

10-
For example, we can put there a table row `<tr>`:
10+
Per esempio, possiamo possiamo inserire una riga di una tabella `<tr>`:
1111
```html
1212
<template>
1313
<tr>
14-
<td>Contents</td>
14+
<td>Contenuti</td>
1515
</tr>
1616
</template>
1717
```
1818

19-
Usually, if we try to put `<tr>` inside, say, a `<div>`, the browser detects the invalid DOM structure and "fixes" it, adds `<table>` around. That's not what we want. On the other hand, `<template>` keeps exactly what we place there.
19+
Solitamente, se proviamo a inserire un `<tr>` per esempio dentro un `<div>`, il browser riconoscerà una struttura non valida, "correggendola", aggiungendovi una tabella attorno. Questo non è il comportamento designato, e d'altra parte `<template>` mantiene le cose esattamente come le inseriamo.
2020

21-
We can put styles and scripts into `<template>` as well:
21+
Possiamo anche inserire stili e scripts dentro i `<template>`:
2222

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

34-
The browser considers `<template>` content "out of the document": styles are not applied, scripts are not executed, `<video autoplay>` is not run, etc.
34+
Il browser considera il contenuto di `<template>` "avulso dal documento": gli stili non verranno applicati, gli script non verranno eseguiti, i `<video autoplay>` non verranno partiranno in automatico, etc.
3535

36-
The content becomes live (styles apply, scripts run etc) when we insert it into the document.
36+
Il contenuto diventa vivo (gli stili vengono applicati, gli script vengono eseguiti, etc) solo quando andiamo ad inserirlo dentro il documento.
3737

38-
## Inserting template
38+
## Inserimento del template
3939

40-
The template content is available in its `content` property as a [DocumentFragment](info:modifying-document#document-fragment) -- a special type of DOM node.
40+
Il contenuto del template è disponibile nella proprietà `content` come [DocumentFragment](info:modifying-document#document-fragment), un particolare tipo di nodo DOM.
4141

42-
We can treat it as any other DOM node, except one special property: when we insert it somewhere, its children are inserted instead.
42+
Possiamo trattarlo come ogni altro nodo del DOM, tranne per una sua peculiarità: quando lo inseriamo da qualche parte, come DocumentFragment, vengono inseriti i suoi figli.
4343

44-
For example:
44+
Per esempio:
4545

4646
```html run
4747
<template id="tmpl">
@@ -55,24 +55,24 @@ For example:
5555
let elem = document.createElement('div');
5656
5757
*!*
58-
// Clone the template content to reuse it multiple times
58+
// Clona il contenuto del template per riutilizzarlo più volte
5959
elem.append(tmpl.content.cloneNode(true));
6060
*/!*
6161
6262
document.body.append(elem);
63-
// Now the script from <template> runs
63+
// Ora lo script dentro <template> viene eseguito
6464
</script>
6565
```
6666

67-
Let's rewrite a Shadow DOM example from the previous chapter using `<template>`:
67+
Riscriviamo un esempio di Shadow DOM, preso dal capitolo precedente, usando però `<template>`:
6868

6969
```html run untrusted autorun="no-epub" height=60
7070
<template id="tmpl">
7171
<style> p { font-weight: bold; } </style>
7272
<p id="message"></p>
7373
</template>
7474

75-
<div id="elem">Click me</div>
75+
<div id="elem">Cliccami</div>
7676

7777
<script>
7878
elem.onclick = function() {
@@ -82,14 +82,14 @@ Let's rewrite a Shadow DOM example from the previous chapter using `<template>`:
8282
elem.shadowRoot.append(tmpl.content.cloneNode(true)); // (*)
8383
*/!*
8484
85-
elem.shadowRoot.getElementById('message').innerHTML = "Hello from the shadows!";
85+
elem.shadowRoot.getElementById('message').innerHTML = "Saluti dalle ombre!";
8686
};
8787
</script>
8888
```
8989

90-
In the line `(*)` when we clone and insert `tmpl.content`, as its `DocumentFragment`, its children (`<style>`, `<p>`) are inserted instead.
90+
Nella riga `(*)` quando cloniamo ed inseriamo `tmpl.content`, come `DocumentFragment`, vengono inseriti i suoi figli (`<style>`, `<p>`).
9191

92-
They form the shadow DOM:
92+
Questi formano lo shadow DOM:
9393

9494
```html
9595
<div id="elem">
@@ -99,18 +99,18 @@ They form the shadow DOM:
9999
</div>
100100
```
101101

102-
## Summary
102+
## Riepilogo
103103

104-
To summarize:
104+
Per riepilogare:
105105

106-
- `<template>` content can be any syntactically correct HTML.
107-
- `<template>` content is considered "out of the document", so it doesn't affect anything.
108-
- We can access `template.content` from JavaScript, clone it to reuse in a new component.
106+
- il contenuto di `<template>` può essere qualunque HTML sintatticamente corretto.
107+
- i contenuto di `<template>` viene considerato "avulso dal documento", quindi non modificherà o eseguirà alcunché.
108+
- Possiamo accedere a `template.content` via JavaScript, clonarlo per poterlo riutilizzare in un nuovo componente.
109109

110-
The `<template>` tag is quite unique, because:
110+
Il tag `<template>` è unico, perché:
111111

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>`).
114-
- The content becomes interactive: scripts run, `<video autoplay>` plays etc, when inserted into the document.
112+
- Il browser controlla la sintassi HTML al suo interno (diversamente dall'uso di un template string dentro uno script).
113+
- ...Tuttavia è permesso l'uso di tag HTML top-level, anche quelli che non avrebbero alcun senso se privi del loro appropriato contenitore (per esempio i `<tr>`).
114+
- Il contenuto diventa interattivo (gli scripts vengono eseguiti, i `<video autoplay>` partono, etc) quando viene inserito dentro il documento.
115115

116-
The `<template>` element does not feature any iteration mechanisms, data binding or variable substitutions, but we can implement those on top of it.
116+
L'elemento `<template>` non comprende alcun tipo di meccanismo di interazione, data binding o sostituzioni di variabili, ma possiamo implementarli su di essi.

0 commit comments

Comments
 (0)