Skip to content

Commit 57a3a4d

Browse files
committed
docs: add more info for v3.1.0
1 parent eed8210 commit 57a3a4d

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

docs/versions/v3/language-elements/directives.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,29 @@ When defining a layout file for your template, you can reserve placeholders for
175175
</html>
176176
```
177177

178+
### Fallback Argument
179+
180+
As a second argument, `@reserve` can also take a fallback value that will be used if no corresponding `@insert` is defined in the template. Example:
181+
182+
```textwire
183+
<!DOCTYPE html>
184+
<html lang="en">
185+
<head>
186+
<meta charset="UTF-8">
187+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
188+
<title>@reserve("title", "Welcome to Textwire")</title>
189+
</head>
190+
<body>
191+
@reserve("content", "There is nothing here")
192+
</body>
193+
</html>
194+
```
195+
178196
### Important notes
179197

180-
- **Takes one argument.** `@reserve` directive accepts a single argument: the name of the reserved placeholder. This name will be used in the [`@insert`](#insert) directive to insert content into the corresponding placeholder.
181198
- **Only in layout files.** `@reserve` can only be used inside layout file. Using it in templates and components will result in error.
182199
- **`@insert` is optional.** `@reserve` does not force you to have a matching `@insert`. If you don't insert any value into `@reseve`, it will fallback to an empty string.
200+
- **One `@reserve` per file.** You cannot define multiple `@reserve` directives with the same name in a single layout file. It will result in an error starting from version [v3.1.0](https://github.com/textwire/textwire/pull/68).
183201
- **Can be passed to components.** If you want to pass the value of `@reserve` from layout into a component, you can pass it using [slots](/v3/language-elements/directives#slot). Example:
184202
```textwire :no-line-numbers
185203
@component('header')
@@ -285,6 +303,7 @@ In this example, both default and named slots are used within a single component
285303
- **Duplicate names not allowed.** Defining multiple default slots or named slots with the same name in a single component will result in an error.
286304
- **Empty string is default slot.** If you provide an empty string as a slot name, it will act as default slot. `@slot` and `@slot('')` act the same.
287305
- **Slots have current context.** Slots have the context of the same file where they are defined. It means you can dinamically modify the content of a slot before it get rendered in the component file.
306+
- **Optional.** External slots that live inside the component file are optional. If you don't provide content for a slot, it will be rendered as an empty string.
288307

289308
## @dump
290309

0 commit comments

Comments
 (0)