Skip to content

Commit 190bc91

Browse files
authored
Merge pull request #148 from abdmmar/abdmmar-branch
Template Element - Elemen Template
2 parents 223ccce + 91bbe2d commit 190bc91

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

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

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

2-
# Template element
2+
# Elemen template
33

4-
A built-in `<template>` element serves as a storage for HTML markup templates. The browser ignores it contents, only checks for syntax validity, but we can access and use it in JavaScript, to create other elements.
4+
Elemen `<template>` bawaan berfungsi sebagai penyimpanan untuk template markup HTML. Browser mengabaikan isinya, hanya memeriksa validitas sintaks, tetapi kita dapat mengakses dan menggunakannya dalam JavaScript, untuk membuat elemen lain.
55

6-
In theory, we could create any invisible element somewhere in HTML for HTML markup storage purposes. What's special about `<template>`?
6+
Secara teori, kita bisa membuat elemen tak terlihat di suatu tempat di HTML untuk tujuan penyimpanan markup HTML. Apa yang spesial dari `<template>`?
77

8-
First, its content can be any valid HTML, even if it normally requires a proper enclosing tag.
8+
Pertama, isinya dapat berupa HTML yang valid, meskipun biasanya membutuhkan tag penutup yang tepat.
99

10-
For example, we can put there a table row `<tr>`:
10+
Misalnya, kita dapat meletakkan baris tabel `<tr>` di dalamnya:
1111
```html
1212
<template>
1313
<tr>
@@ -16,9 +16,9 @@ For example, we can put there a table row `<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+
Biasanya, jika kita mencoba untuk meletakkan `<tr>` di dalam, katakanlah, sebuah `<div>`, browser mendeteksi struktur DOM yang tidak valid dan "memperbaikinya", menambahkan `<table>` di sekitarnya. Bukan itu yang kita inginkan. Di sisi lain, `<template>` menyimpan persis apa yang kita tempatkan di sana.
2020

21-
We can put styles and scripts into `<template>` as well:
21+
Kita juga bisa menempatkan gaya dan skrip ke dalam `<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+
Browser menganggap konten `<template>` berada "di luar dokumen": gaya tidak diterapkan, skrip tidak dijalankan, `<video autoplay>` tidak dijalankan, dll.
3535

36-
The content becomes live (styles apply, scripts run etc) when we insert it into the document.
36+
Konten menjadi hidup (gaya css diterapkan, skrip dijalankan, dll.) Ketika kita memasukkannya ke dalam dokumen.
3737

38-
## Inserting template
38+
## Memasukkan 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+
Konten template tersedia dalam properti `content` sebagai [DocumentFragment](info:modifying-document#document-fragment) -- yaitu jenis khusus dari simpul 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+
Kita bisa memperlakukannya sebagai simpul DOM lainnya, kecuali satu properti khusus: ketika kita memasukkannya ke suatu tempat, anak-anaknya akan dimasukkan.
4343

44-
For example:
44+
Sebagai contoh:
4545

4646
```html run
4747
<template id="tmpl">
@@ -55,16 +55,16 @@ For example:
5555
let elem = document.createElement('div');
5656
5757
*!*
58-
// Clone the template content to reuse it multiple times
58+
// Menggandakan konten template untuk digunakan kembali beberapa kali
5959
elem.append(tmpl.content.cloneNode(true));
6060
*/!*
6161
6262
document.body.append(elem);
63-
// Now the script from <template> runs
63+
// Sekarang skrip dari <template> berjalan
6464
</script>
6565
```
6666

67-
Let's rewrite a Shadow DOM example from the previous chapter using `<template>`:
67+
Mari kita tulis ulang contoh Shadow DOM dari bab sebelumnya menggunakan `<template>`:
6868

6969
```html run untrusted autorun="no-epub" height=60
7070
<template id="tmpl">
@@ -87,9 +87,9 @@ 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`, as its `DocumentFragment`, its children (`<style>`, `<p>`) are inserted instead.
90+
Di baris `(*)` saat kita menggandakan dan memasukkan `tmpl.content`, sebagai ` DocumentFragment`-nya, turunannya (`<style>`, `<p>`) akan disisipkan.
9191

92-
They form the shadow DOM:
92+
Mereka membentuk 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+
## Ringkasan
103103

104-
To summarize:
104+
Untuk meringkas:
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+
- `<template>` konten dapat berupa HTML yang benar secara sintaksis.
107+
- `<template>` konten dianggap "di luar dokumen", jadi tidak memengaruhi apa pun.
108+
- Kita dapat mengakses `template.content` dari JavaScript, mengkloningnya untuk digunakan kembali dalam komponen baru.
109109

110-
The `<template>` tag is quite unique, because:
110+
Tag `<template>` cukup unik, karena:
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+
- Browser memeriksa sintaks HTML di dalamnya (sebagai lawan menggunakan string template di dalam skrip).
113+
- ...Namun tetap mengizinkan penggunaan tag HTML tingkat atas, bahkan yang tidak masuk akal tanpa pembungkus yang tepat (mis. `<tr>`).
114+
- Konten menjadi interaktif: skrip dijalankan, `<video autoplay>` memutar dll, ketika dimasukkan ke dalam dokumen.
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+
Elemen `<template>` tidak menampilkan mekanisme iterasi, pengikatan data, atau substitusi variabel, tetapi kita dapat mengimplementasikannya di atasnya.

0 commit comments

Comments
 (0)