You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/tutorials/render-file.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,6 +100,23 @@ var engine = new Liquid({
100
100
101
101
{% note warn Path Traversal Vulnerability %}The default value of <code>contains()</code> always returns true. That means when specifying an abstract file system, you'll need to provide a proper <code>contains()</code> to avoid expose such vulnerabilities.{% endnote %}
102
102
103
+
## In-memory Template
104
+
105
+
To facilitate rendering w/o files, there's a `templates` option to specify a mapping of filenames and their content. LiquidJS will read templates from the mapping.
106
+
107
+
```typescript
108
+
const engine =newLiquid({
109
+
templates: {
110
+
'views/entry': 'header {% include "../partials/footer" %}',
111
+
'partials/footer': 'footer'
112
+
}
113
+
})
114
+
engine.renderFileSync('views/entry'))
115
+
// Result: 'header footer'
116
+
```
117
+
118
+
Note that file system options like `root`, `layouts`, `partials`, `relativeReference` will be ignored when `templates` is specified.
/** `fs` is used to override the default file-system module with a custom implementation. */
66
67
fs?: FS;
68
+
/** Render from in-memory `templates` mapping instead of file system. File system related options like `fs`, 'root', and `relativeReference` will be ignored when `templates` is specified. */
69
+
templates?: {[key: string]: string};
67
70
/** the global scope passed down to all partial and layout templates, i.e. templates included by `include`, `layout` and `render` tags. */
68
71
globals?: object;
69
72
/** Whether or not to keep value type when writing the Output, not working for streamed rendering. Defaults to `false`. */
0 commit comments