You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/versions/v3/functions/guide.md
+4-15Lines changed: 4 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ description: Discover correct syntax for Textwire functions and learn about diff
4
4
---
5
5
6
6
# Functions Guide
7
+
7
8
Each function is attached to a specific data type. For example, the `len` function is used to get the length of an array, and the `trim` function is used to remove characters from both sides of the string. You can call a function on a value by using the dot operator (`.`) followed by the function name.
8
9
9
10
```textwire
@@ -16,26 +17,14 @@ You can also chain multiple functions together to perform complex operations.
Learn about [error handling](/v3/guides/error-handling) in Textwire when you call a function that doesn't exist, or when you pass incorrect arguments
21
-
:::
22
-
23
-
## Unicode Friendly
24
-
Textwire is designed to be Unicode friendly to satisfy the needs of developers from different countries. All built-in functions handle Unicode characters and strings without any issues.
25
-
26
-
All the built-in functions in Textwire are Unicode friendly, which means they can handle Unicode characters and strings without any issues. You can use these functions to manipulate strings in any language. For example:
27
21
28
-
```textwire
29
-
{{ "我喜欢中国".len() }} <!-- output: 5 -->
30
-
```
22
+
## Unicode Support
31
23
32
-
Or:
33
-
34
-
```textwire
35
-
{{ "привет".at(2) }} <!-- output: и -->
36
-
```
24
+
Textwire's built-in functions fully support Unicode characters and strings. Whether you're working with emojis, accented characters, or non-Latin scripts, all functions work correctly. Learn more in the [Unicode](/v3/#unicode) section.
37
25
38
26
## Suggest a new function
27
+
39
28
New functions are added in new version of Textwire when there is a need for them. You can follow the updates in our [Release Notes](https://github.com/textwire/textwire/blob/master/CHANGELOG.md) on GitHub.
40
29
41
30
If you have a suggestion for a new function that might benefit everybody using Textwire, please open [an issue](https://github.com/textwire/textwire/issues/new) on GitHub if it's an important function to add.
Copy file name to clipboardExpand all lines: docs/versions/v3/index.md
+39Lines changed: 39 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
1
---
2
2
title: Introduction - v3
3
3
description: Get an overview of Textwire, a powerful template evaluator for Go developers, and learn about its features, syntax, and various use cases
4
+
outline: deep
4
5
---
5
6
6
7
# Introduction
8
+
7
9
Textwire is a domain-specific language (DSL) tailored for Go projects as a templating language, designed to embed dynamic content into text-based formats like HTML, XML, JSON, or any other format.
8
10
9
11
Built specifically for Go, Textwire offers a clean and intuitive syntax that simplifies the injection of variables and logic into any text-based format.
@@ -19,6 +21,7 @@ The syntax is designed to be familiar and easy-to-learn, particularly for develo
19
21
## How to Use It
20
22
21
23
You can use Textwire in three different ways:
24
+
22
25
1.[As a templating engine for web applications](/v3/guides/template-usage)
23
26
2.[To embed dynamic content into strings](/v3/guides/eval-string)
24
27
3.[To embed dynamic content into files](/v3/guides/eval-file)
@@ -44,8 +47,42 @@ Below is a simple example of a Textwire template:
44
47
@end
45
48
```
46
49
50
+
## Unicode Support
51
+
52
+
Textwire fully embraces Unicode, making it ideal for international applications and multilingual content. Whether you're building websites in Chinese, Russian, Arabic, or mixing multiple languages, Textwire handles it seamlessly.
53
+
54
+
### String Functions
55
+
56
+
All built-in functions properly handle Unicode characters. They count characters correctly (not bytes) and support any language:
57
+
58
+
```textwire :no-line-numbers
59
+
{{ "我喜欢中国".len() }} <!-- output: 5 (characters, not bytes) -->
60
+
{{ "привет".at(2) }} <!-- output: и -->
61
+
```
62
+
63
+
Keep in mind that with emojis it could be tricky, because some emojis are represented by multiple Unicode code points. The example below shows that the string "👋🏽🌍" has a length of 3, because the waving hand emoji with medium skin tone (👋🏽) is represented by two code points, while the globe emoji (🌍) is represented by one code point:
64
+
65
+
```textwire :no-line-numbers
66
+
{{ "👋🏽🌍".len() }} <!-- output: 3 -->
67
+
```
68
+
69
+
### File Names
70
+
71
+
Directives that accept file names—like `@component`, `@use`, `@insert`, `@reserve`, and `@slot`—fully support Unicode paths:
72
+
73
+
```textwire :no-line-numbers
74
+
@component('书', { name })
75
+
@use('♥️/главная')
76
+
```
77
+
78
+
:::warning No Unicode for Identifiers
79
+
Unicode characters cannot be used in variable names, function names, or object fields. Only ASCII letters (a-z, A-Z), digits (0-9), and underscores are allowed. For example, `user_name` is valid, but `用户名` and `имя` are not.
80
+
:::
81
+
47
82
## Mathematical Expressions
83
+
48
84
Textwire operates similarly to Go when it comes to mathematical expressions. You can use the following operators in your templates:
85
+
49
86
- Addition: `+` (`a + b`)
50
87
- Subtraction: `-` (`a - b`)
51
88
- Multiplication: `*` (`a * b`)
@@ -70,6 +107,8 @@ Type mismatching is not supported when performing mathematical operations. For e
70
107
:::
71
108
72
109
## Reserved Variable Names
110
+
73
111
Textwire has two reserved variable names that you cannot use:
112
+
74
113
1.`loop` Object that is used inside loops. [Read more](/v3/guides/loops#loop-variables)
75
114
2.`global` Global object available in all Textwire files. [Read more](/v3/guides/configurations#global-data)
0 commit comments