mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 15:00:42 -07:00
docs: clarification on how to disable tags/filters, see #324
This commit is contained in:
@@ -37,3 +37,25 @@ engine.registerFilter('add', (initial, arg1, arg2) => initial + arg1 + arg2)
|
|||||||
```
|
```
|
||||||
|
|
||||||
See existing filter implementations here: <https://github.com/harttle/liquidjs/tree/master/src/builtin/filters>
|
See existing filter implementations here: <https://github.com/harttle/liquidjs/tree/master/src/builtin/filters>
|
||||||
|
|
||||||
|
## Unregister Tags/Filters
|
||||||
|
|
||||||
|
In some cases it's desirable to disable some tags/filters (see [#324](https://github.com/harttle/liquidjs/issues/324)), you'll need to register a dummy tag/filter in which an corresponding Error throws.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// disable a tag
|
||||||
|
const disabledTag = {
|
||||||
|
parse: function(token) {
|
||||||
|
throw new Error(`tag "${token.name}" disabled`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
engine.registerTag('include', disabledTag);
|
||||||
|
|
||||||
|
// disable a filter
|
||||||
|
function disabledFilter(name) {
|
||||||
|
return function () {
|
||||||
|
throw new Error(`filter "${name}" disabled`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
engine.registerFilter('plus', disabledFilter('plus'));
|
||||||
|
```
|
||||||
|
|||||||
@@ -37,3 +37,25 @@ engine.registerFilter('add', (initial, arg1, arg2) => initial + arg1 + arg2)
|
|||||||
```
|
```
|
||||||
|
|
||||||
查看已有的过滤器实现:<https://github.com/harttle/liquidjs/tree/master/src/builtin/filters>
|
查看已有的过滤器实现:<https://github.com/harttle/liquidjs/tree/master/src/builtin/filters>
|
||||||
|
|
||||||
|
## 反注册标签/过滤器
|
||||||
|
|
||||||
|
有时可能需要禁用一些标签/过滤器(比如 [#324](https://github.com/harttle/liquidjs/issues/324)),注册一个假的标签/过滤器并在里面抛出相应的错误即可。
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// 禁用标签
|
||||||
|
const disabledTag = {
|
||||||
|
parse: function(token) {
|
||||||
|
throw new Error(`tag "${token.name}" disabled`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
engine.registerTag('include', disabledTag);
|
||||||
|
|
||||||
|
// 禁用过滤器
|
||||||
|
function disabledFilter(name) {
|
||||||
|
return function () {
|
||||||
|
throw new Error(`filter "${name}" disabled`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
engine.registerFilter('plus', disabledFilter('plus'));
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user