Skip to content

Commit fa212fe

Browse files
committed
add template return type selection guide
1 parent 5134ccc commit fa212fe

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,19 @@ This is just a file with access to global vars: ${testVar}`,
875875
export default templateIterator
876876
```
877877

878+
### Choosing a template return type
879+
880+
Use the simplest return type that fits your needs:
881+
882+
| Return type | Multiple outputs | Custom filename | Use when |
883+
|---|---|---|---|
884+
| String | No | No (derived from template filename) | Single file, filename from template name |
885+
| Object | No | Yes | Single file with a custom output path |
886+
| Array | Yes | Yes | Fixed set of output files known at build time |
887+
| AsyncIterator | Yes | Yes | Any async work, or a dynamic number of outputs |
888+
889+
Start with a string return and only switch to a more complex type when you need what it provides. An async generator is the right choice when you need to do async work (such as calling `renderInnerPage` on multiple pages) and produce more than one output file.
890+
878891
### RSS Feed Template Example
879892

880893
Templates receive the standard variables available to pages, so its possible to perform page introspection and generate RSS feeds of website content.

0 commit comments

Comments
 (0)