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
+7-13Lines changed: 7 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,26 +45,20 @@ It can be a string-typed path (see above example), or a list of root directories
45
45
46
46
```javascript
47
47
var engine =newLiquid({
48
-
root: ['views/', 'views/partials/'],
48
+
root: ['views/'],
49
+
partials: ['views/partials/'],
50
+
layouts: ['views/layouts/'],
49
51
extname:'.liquid'
50
52
});
51
53
```
52
54
53
55
{% note tip Relative Paths %}Relative paths in <code>root</code> will be resolved against <code>cwd()</code>.{% endnote %}
54
56
55
-
When `{% raw %}{% render "foo" %}{% endraw %}` is rendered or `liquid.renderFile('foo')` is called, the following files will be looked up and the first existing file will be used:
57
+
- When `parse()`, `render()` functions are called, for example `liquid.renderFile('foo')`, templates under `root` will be looked up.
58
+
- When a partial is requested, for example `{% raw %}{% render "foo" %}{% endraw %}`, templates under `partials` will be looked up.
59
+
- When a layout is requested, for example `{% raw %}{% layout "foo" %}{% endraw %}`, templates under `layouts` will be looked up.
56
60
57
-
-`cwd()`/views/foo.liquid
58
-
-`cwd()`/views/partials/foo.liquid
59
-
60
-
If none of the above files exists, an `ENOENT` error will be thrown. Here's a demo for Node.js: [demo/nodejs](https://github.com/harttle/liquidjs/tree/master/demo/nodejs).
61
-
62
-
When LiquidJS is used in browser, say current location is <https://example.com/bar/index.html>, only the first `root` will be used and the file to be fetched is:
63
-
64
-
-<https://example.com/bar/foo.liquid>
65
-
66
-
If fetch fails, a 404/500 error or network failures for example, an `ENOENT` error will be thrown.
67
-
Here's a demo for browsers: [demo/browser](https://github.com/harttle/liquidjs/tree/master/demo/browser).
61
+
When LiquidJS is used in browser, the paths will be resolved based on current location. Here's a demo for browsers: [demo/browser](https://github.com/harttle/liquidjs/tree/master/demo/browser).
0 commit comments