Skip to content

Commit 9bfd116

Browse files
committed
template
1 parent 82cb376 commit 9bfd116

File tree

4 files changed

+66
-44
lines changed

4 files changed

+66
-44
lines changed

en/api.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# API Reference
2+
3+
## Top-Level APIs
4+
5+
### `createRenderer`
6+
7+
### `createBundleRenderer`
8+
9+
## Renderer Options
10+
11+
### `basedir`
12+
13+
### `cache`
14+
15+
### `directives`
16+
17+
### `template`
18+
19+
### `clientManifest`
20+
21+
### `inject`
22+
23+
### `shouldPreload`
24+
25+
### `runInNewContext`

en/basic.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,43 @@ renderer.renderToString(app, (err, html) => {
103103
})
104104
```
105105

106-
The template also supports many advanced features like:
106+
### Template Interpolation
107+
108+
The template also supports simple interpolation. Given the following template:
109+
110+
``` html
111+
<html>
112+
<head>
113+
<title>{{ title }}</title>
114+
{{{ meta }}}
115+
</head>
116+
<body>
117+
<!--vue-ssr-outlet-->
118+
</body>
119+
</html>
120+
```
121+
122+
We can provide interpolation data by passing a "render context object" as the second argument to `renderToString`:
123+
124+
``` js
125+
const context = {
126+
title: 'hello',
127+
meta: `
128+
<meta ...>
129+
<meta ...>
130+
`
131+
}
132+
133+
renderer.renderToString(app, context, (err, html) => {
134+
// page title will be "hello"
135+
// with meta tags injected
136+
})
137+
```
138+
139+
The `context` object can also be shared with the Vue app instance, allowing components to dynamically register data for template interpolation.
140+
141+
In addition, the template supports some advanced features such as:
107142

108-
- Interpolation using a render context;
109143
- Auto injection of critical CSS when using `*.vue` components;
110144
- Auto injection of asset links and resource hints when using `clientManifest`;
111145
- Auto injection and XSS prevention when embedding Vuex state for client-side hydration.

en/build-config.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ With this setup, your server-rendered HTML for a build with code-splitting will
136136

137137
### Manual Asset Injection
138138

139-
Sometimes you might want finer-grained control over how assets are injected into the template, or maybe you are not using a template at all. In the `renderToString` callback, the `context` object you passed in will expose the following methods:
139+
By default, asset injection is automatic when you provide the `template` render option. But sometimes you might want finer-grained control over how assets are injected into the template, or maybe you are not using a template at all. In such a case, you can pass `inject: false` when creating the renderer and manually perform asset injection.
140+
141+
In the `renderToString` callback, the `context` object you passed in will expose the following methods:
140142

141143
- `context.renderStyles()`
142144

@@ -176,11 +178,12 @@ Sometimes you might want finer-grained control over how assets are injected into
176178

177179
Preloaded files can be further customized with the `shouldPreload` option.
178180

179-
Since the `template` passed to `createBundleRenderer` will be interpolated using `context`, you can make use of these methods inside the template (make sure to use triple-mustaches):
181+
Since the `template` passed to `createBundleRenderer` will be interpolated using `context`, you can make use of these methods inside the template (with `inject: false`):
180182

181183
``` html
182184
<html>
183185
<head>
186+
<!-- use triple mustache for non-HTML-escaped interpolation -->
184187
{{{ renderResourceHints() }}}
185188
{{{ renderStyles() }}}
186189
</head>

en/template.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)