Add 3. Variables
parent
1e310c8797
commit
fad22fa680
1 changed files with 43 additions and 0 deletions
43
3.-Variables.md
Normal file
43
3.-Variables.md
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
Hylia introduces Variables, a core component in many code languages not present in HTML.
|
||||||
|
To create a variable, we can use the `<var>` tag.
|
||||||
|
A `<var>` tag is structured as follows:
|
||||||
|
|
||||||
|
`<var name="CoolVariable">CoolValue</var>`
|
||||||
|
|
||||||
|
Now how do we use these variables?
|
||||||
|
|
||||||
|
We can use `{{VarName}}` to call them. That's the variable name wrapped in two curly brackets `{{ }}`
|
||||||
|
|
||||||
|
Here is a basic Hylia file using them.
|
||||||
|
|
||||||
|
```html
|
||||||
|
<hylia>
|
||||||
|
<element name="head">
|
||||||
|
<title>Hello Hylia!</title>
|
||||||
|
</element>
|
||||||
|
<var name="testvar">Hi!</var>
|
||||||
|
<element name="body">
|
||||||
|
<h1>Hello Hylia!</h1>
|
||||||
|
<p>This is an example content.</p>
|
||||||
|
{{testvar}}
|
||||||
|
</element>
|
||||||
|
</hylia>
|
||||||
|
```
|
||||||
|
When the file is compiled, It replaces `{{testvar}}` with the value of the `testvar` variable.
|
||||||
|
Variables can contain tags, as long as they're oneliners:
|
||||||
|
`<var name="testvar"><h1>Hello!</h1></var>`
|
||||||
|
|
||||||
|
```
|
||||||
|
<hylia>
|
||||||
|
<element name="head">
|
||||||
|
<title>Hello Hylia!</title>
|
||||||
|
</element>
|
||||||
|
<var name="testvar"><h1>Hello!</h1></var>
|
||||||
|
<element name="body">
|
||||||
|
<h1>Hello Hylia!</h1>
|
||||||
|
<p>This is an example content.</p>
|
||||||
|
{{testvar}}
|
||||||
|
</element>
|
||||||
|
</hylia>
|
||||||
|
```
|
||||||
|
Compiling this file will replace `{{testvar}}` with `<h1>Hello!</h1>` in the output.
|
Loading…
Reference in a new issue