忽略树枝中的未知标签
我有几组用 Twig 编写的模板。然后我编写了一个单独的脚本以使用 CLI 运行。该脚本允许我扫描我的模板并编译我的 Assetic 资产。
问题是我有一些自定义的 Twig 令牌解析器供应用程序使用,但是脚本不需要它们来扫描和编译我的资产。其中一些标签非常复杂,需要完整的应用程序才能发挥作用。
有没有一种简单的方法可以让 Twig 忽略未知标签?
一种可能的解决方案是创建一个虚拟令牌解析器并为其指定与标签相同的名称,但这对我来说似乎很黑客,我想避免走这条路。
I have a few set of templates written with Twig. I have then written a separate script to be run using the CLI. This script allows me to scan my templates and compile my Assetic assets.
The problem is that I have a few custom Twig token parsers to be used by the application, however, they are not needed by the script to scan and compile my Assets. Some of these tags are quite complicated and require the full application to function.
Is there a simple way to get Twig to ignore unknown tags?
One possible solution would be to create a dummy token parser and give it the same name as the tag, but this seems very hackish to me and I would like to avoid going down this path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是编写了一个令牌解析器,将令牌解析器移动到块的末尾。
我还提供了一种在构造函数中设置“令牌名称”的方法:
$twig->addTokenParser(new DummyTokenParser('abc'));
这将允许 DummyTokenParser 接管名为
abc
的标签。人们可以用它来替换多种类型的标签:
I simply wrote a token parser that moves the token parser to the end of the block.
I also included a way to set the 'token name' in the constructor:
$twig->addTokenParser(new DummyTokenParser('abc'));
This would allow the DummyTokenParser to take over for the tags called
abc
.One can use it to replace multiple types of tags: