Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
georgelemon authored Feb 23, 2024
1 parent 0ece7f0 commit 7def2a2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ Note that this feature is not available when compiling with `-d:release`.
Tim provides 3 types of data storages. **Global** and **Local** as JsonNode objects for handling immutable data from the app to your `timl` templates,
and **Template** based data at template level using Tim's built-in AST-based interpreter.

Global data can be passed at precompile-time and is made available globally for all layouts, views and partials.
1. **Global data** can be passed at precompile-time and is made available globally for all layouts, views and partials.<br>
Note: Using `$app` in a template will mark it as JIT.
```nim
timl.precompile(
global = %*{
Expand All @@ -118,26 +119,27 @@ footer > div.container > div.row > div.col-12
small: "&copy; " & $app.year & " &mdash; Made by Humans from OpenPeeps"
```

Local data can be passed to a template from route's callback (controller).
`$this` constant can be used to access data from the local storage.
2. **Local data** can be passed to a template from route's callback (controller).
`$this` constant can be used to access data from the local storage.<br>
Note: Using `$this` in a template will mark it as JIT.

```nim
timl.render("index", local = %*{
isLoggedin: true,
loggedin: true,
username: "Johnny Boy"
})
```

```timl
if $this.isLoggeding:
if $this.loggedin:
h1.fw-bold: "Hello, " & $this.username
a href="/logout": "Log out"
else:
h1: "Hello!"
a href="/login": "Please login to view this page"
```

Template variables can be declared inside templates using `var` or `const`. The only difference
3. **Template variables** can be declared inside templates using `var` or `const`. The only difference
between these two is that constants are immutable and requires initialization.

The scope of a declared variable is limited to the branch in which it was declared.
Expand Down

0 comments on commit 7def2a2

Please sign in to comment.