Skip to content

Commit 286b23d

Browse files
committed
Update article.md
Template element
1 parent f17c577 commit 286b23d

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

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

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

22
# Template element
33

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.
4+
عنصر داخلی <template> به‌عنوان یک فضای ذخیره‌سازی برای الگوهای HTML (HTML Markup Templates) عمل می‌کند. مرورگر محتوای درون آن را نادیده می‌گیرد و فقط از نظر صحت نگارشی (Syntax) آن را بررسی می‌کند، اما ما می‌توانیم با استفاده از JavaScript به آن دسترسی پیدا کنیم و از آن برای ایجاد عناصر دیگر استفاده کنیم.
55

6-
In theory, we could create any invisible element somewhere in HTML for HTML markup storage purposes. What's special about `<template>`?
6+
از نظر تئوری، ما می‌توانیم هر عنصر نامرئی دیگری را در HTML قرار دهیم تا به‌عنوان فضای ذخیره‌سازی برای کد HTML استفاده شود. پس چه چیزی <template> را خاص می‌کند؟
77

8-
First, its content can be any valid HTML, even if it normally requires a proper enclosing tag.
8+
اول اینکه، محتوای آن می‌تواند هر کد HTML معتبری باشد، حتی اگر در حالت معمول نیاز به تگ محصورکننده‌ی مناسب داشته باشد.
9+
10+
برای مثال، ما می‌توانیم یک ردیف جدول <tr> را درون آن قرار دهیم:
911

10-
For example, we can put there a table row `<tr>`:
1112
```html
1213
<template>
1314
<tr>
@@ -16,9 +17,9 @@ For example, we can put there a table row `<tr>`:
1617
</template>
1718
```
1819

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.
20+
معمولاً اگر سعی کنیم تگ `<tr>` را داخل مثلاً یک `<div>` قرار دهیم، مرورگر ساختار نامعتبر DOM را تشخیص می‌دهد و آن را "اصلاح" می‌کند؛ یعنی به‌طور خودکار یک `<table>` به اطراف آن اضافه می‌کند. اما این چیزی نیست که ما بخواهیم. در عوض، `<template>` دقیقاً همان چیزی را که درونش قرار می‌دهیم، بدون تغییر نگه می‌دارد.
2021

21-
We can put styles and scripts into `<template>` as well:
22+
ما حتی می‌توانیم استایل‌ها و اسکریپت‌ها را نیز داخل `<template>` قرار دهیم:
2223

2324
```html
2425
<template>
@@ -30,18 +31,17 @@ We can put styles and scripts into `<template>` as well:
3031
</script>
3132
</template>
3233
```
34+
مرورگر محتوای درون `<template>` را «خارج از سند» در نظر می‌گیرد: استایل‌ها اعمال نمی‌شوند، اسکریپت‌ها اجرا نمی‌شوند، تگ `<video autoplay>` پخش نمی‌شود و غیره.
3335

34-
The browser considers `<template>` content "out of the document": styles are not applied, scripts are not executed, `<video autoplay>` is not run, etc.
35-
36-
The content becomes live (styles apply, scripts run etc) when we insert it into the document.
36+
وقتی این محتوا را وارد سند (document) کنیم، فعال می‌شود (استایل‌ها اعمال می‌شوند، اسکریپت‌ها اجرا می‌شوند و غیره).
3737

38-
## Inserting template
38+
## وارد کردن 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+
محتوای یک template از طریق ویژگی `content` آن در دسترس است که یک [DocumentFragment](info:modifying-document#document-fragment) محسوب می‌شود — نوع خاصی از گره 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+
می‌توانیم با آن مانند هر گره‌ی دیگری از DOM رفتار کنیم، با یک تفاوت خاص: زمانی که آن را در جایی قرار می‌دهیم، فقط فرزندانش وارد سند می‌شوند، نه خود `DocumentFragment`.
4343

44-
For example:
44+
برای مثال:
4545

4646
```html run
4747
<template id="tmpl">
@@ -64,7 +64,7 @@ For example:
6464
</script>
6565
```
6666

67-
Let's rewrite a Shadow DOM example from the previous chapter using `<template>`:
67+
بیایید یک مثال از Shadow DOM را از فصل قبلی با استفاده از `<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+
در خط `(*)`، زمانی که `tmpl.content` را کپی کرده و درج می‌کنیم، از آنجایی که یک `DocumentFragment` است، فرزندان آن (یعنی `<style>` و `<p>`) به جای خودش درج می‌شوند.
9191

92-
They form the shadow DOM:
92+
این عناصر، 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+
## خلاصه
103103

104-
To summarize:
104+
برای جمع‌بندی:
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>` می‌تواند هر HTML با ساختار نحوی صحیح باشد.
107+
- محتوای `<template>` به‌عنوان «خارج از سند» در نظر گرفته می‌شود، بنابراین روی چیزی تأثیر نمی‌گذارد.
108+
- ما می‌توانیم از طریق JavaScript به `template.content` دسترسی پیدا کنیم و با کپی کردن آن، در یک کامپوننت جدید استفاده‌اش کنیم.
109109

110-
The `<template>` tag is quite unique, because:
110+
تگ `<template>` ویژگی‌های منحصربه‌فردی دارد، زیرا:
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+
- مرورگر ساختار نحوی HTML داخل آن را بررسی می‌کند (برخلاف استفاده از رشته قالب درون اسکریپت).
113+
- ...اما همچنان اجازه می‌دهد که از هر تگ HTML در سطح بالا استفاده شود، حتی تگ‌هایی که بدون تگ‌های محصورکننده منطقی نیستند (مثل `<tr>`).
114+
- وقتی محتوا وارد سند شود، تعاملی می‌شود: اسکریپت‌ها اجرا می‌شوند، ویدیوهای `<video autoplay>` پخش می‌شوند و غیره.
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+
عنصر `<template>` به‌خودی‌خود هیچ مکانیزمی برای تکرار، اتصال داده‌ها (data binding) یا جایگزینی متغیرها ندارد، اما می‌توانیم این قابلیت‌ها را بر روی آن پیاده‌سازی کنیم.

0 commit comments

Comments
 (0)