Skip to content

Commit 78f71af

Browse files
committed
chore: README updated
1 parent a5678f5 commit 78f71af

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

readme.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,38 @@ You can also use the script tag with the attribute `locals` or you custome attri
9393
<div>My name: Scrum</div>
9494
```
9595

96+
In addition, the use of script tag allow you to use `locals` defined globally to assign data to variables.
97+
98+
```js
99+
posthtml(expressions({ locals: { foo: 'bar' } }))
100+
.process(readFileSync('index.html', 'utf8'))
101+
.then((result) => console.log(result.html))
102+
```
103+
104+
```html
105+
<script locals>
106+
module.exports = {
107+
name: 'Scrum',
108+
foo: locals.foo || 'empty'
109+
}
110+
</script>
111+
112+
<div>My name: {{name}}</div>
113+
<div>Foo: {{foo}}</div>
114+
```
115+
116+
```html
117+
<script locals>
118+
module.exports = {
119+
name: 'Scrum',
120+
foo: locals.foo || 'empty'
121+
}
122+
</script>
123+
124+
<div>My name: {{name}}</div>
125+
<div>Foo: bar</div>
126+
```
127+
96128
### Unescaped Locals
97129

98130
By default, special characters will be escaped so that they show up as text, rather than html code. For example, if you had a local containing valid html as such:
@@ -444,7 +476,7 @@ You can customize the name of the tag:
444476

445477
```js
446478
var opts = {
447-
ignoredTag: 'verbatim',
479+
ignoredTag: 'verbatim',
448480
locals: { foo: 'bar' } }
449481
}
450482

0 commit comments

Comments
 (0)