eq directive
This commit is contained in:
12
README.md
12
README.md
@@ -58,8 +58,9 @@ render("./output", {
|
||||
|
||||
| Directive | Description |
|
||||
|---|---|
|
||||
| `<@if(context.x)>` | Conditional block (must end with `<@endif>`) |
|
||||
| `<@elseif(context.y)>` | Else-if branch |
|
||||
| `<@if(context.x)>` | Conditional block — truthy check (must end with `<@endif>`) |
|
||||
| `<@if(eq(context.x,"value"))>` | Conditional block — string equality check |
|
||||
| `<@elseif(context.y)>` | Else-if branch (same forms as `@if`) |
|
||||
| `<@else>` | Else branch |
|
||||
| `<@endif>` | End conditional block |
|
||||
| `<@var(context.x)>` | Substitute with context value (default type: `string`) |
|
||||
@@ -69,7 +70,8 @@ render("./output", {
|
||||
|
||||
| Directive | Description |
|
||||
|---|---|
|
||||
| `<@if(context.x)>dirname` | Conditionally include directory/file |
|
||||
| `<@if(context.x)>dirname` | Conditionally include directory/file (truthy check) |
|
||||
| `<@if(eq(context.x,"value"))>dirname` | Conditionally include by string equality |
|
||||
| `<@var(context.x)>` | Dynamic directory/file name |
|
||||
|
||||
These can be combined: `<@if(context.web.create)><@var(context.web.dir)>` creates a directory named by `context.web.dir` only if `context.web.create` is true.
|
||||
@@ -117,6 +119,10 @@ render("./output", { web: "not a boolean", header: { show: true, title: "Hi" } }
|
||||
// ZodError: expected boolean, received string at "web"
|
||||
```
|
||||
|
||||
## Re-rendering
|
||||
|
||||
`render(target, context)` clears `target` before writing, so rendering the same template into the same directory with different contexts always produces a clean result (files/paths excluded by conditionals won't linger from a previous run).
|
||||
|
||||
## Unmatched directives
|
||||
|
||||
A `<@if>` without a matching `<@endif>` throws at render time:
|
||||
|
||||
Reference in New Issue
Block a user