diff --git a/docs/source/tutorials/register-filters-tags.md b/docs/source/tutorials/register-filters-tags.md index 3a9f50af8..5005e1f22 100644 --- a/docs/source/tutorials/register-filters-tags.md +++ b/docs/source/tutorials/register-filters-tags.md @@ -37,3 +37,25 @@ engine.registerFilter('add', (initial, arg1, arg2) => initial + arg1 + arg2) ``` See existing filter implementations here: + +## 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')); +``` diff --git a/docs/source/zh-cn/tutorials/register-filters-tags.md b/docs/source/zh-cn/tutorials/register-filters-tags.md index 883ec38f2..9890848dd 100644 --- a/docs/source/zh-cn/tutorials/register-filters-tags.md +++ b/docs/source/zh-cn/tutorials/register-filters-tags.md @@ -37,3 +37,25 @@ engine.registerFilter('add', (initial, arg1, arg2) => initial + arg1 + arg2) ``` 查看已有的过滤器实现: + +## 反注册标签/过滤器 + +有时可能需要禁用一些标签/过滤器(比如 [#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')); +```