Skip to content

Commit

Permalink
Merge branch 'main' of github.com:openpeeps/tim
Browse files Browse the repository at this point in the history
  • Loading branch information
georgelemon committed Feb 26, 2024
2 parents 0f93f7f + 4a69db6 commit 5f1c7d4
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ body
div.row > div.col-12 > h3.fw-bold: "Leave a message"
div#commentForm
@client target="#commentForm"
form method="POST" action="/submitComment"
div.form-floating
input.form-control type="text" name="username"
placeholder="Your name" autocomplete="off" required=""
label: "Your name"
div.form-floating.my-3
textarea.form-control name="message" style="height: 140px" required="": "Your message"
label: "Your message"
div.text-center > button.btn.btn-dark.px-4.rounded-pill type="submit": "Submit your message"
@end
@client target="#commentForm"
form method="POST" action="/submitComment"
div.form-floating
input.form-control type="text" name="username"
placeholder="Your name" autocomplete="off" required=""
label: "Your name"
div.form-floating.my-3
textarea.form-control name="message" style="height: 140px" required="": "Your message"
label: "Your message"
div.text-center > button.btn.btn-dark.px-4.rounded-pill type="submit": "Submit your message"
@end
```

## Browser Sync & Reload
Expand All @@ -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 5f1c7d4

Please sign in to comment.