忽略树枝中的未知标签

发布于 2025-01-05 07:05:31 字数 377 浏览 1 评论 0原文

我有几组用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那请放手 2025-01-12 07:05:32

我只是编写了一个令牌解析器,将令牌解析器移动到块的末尾。

我还提供了一种在构造函数中设置“令牌名称”的方法:
$twig->addTokenParser(new DummyTokenParser('abc'));

这将允许 DummyTokenParser 接管名为 abc 的标签。

人们可以用它来替换多种类型的标签:

$twig->addTokenParser(new DummyTokenParser('tag1'));
$twig->addTokenParser(new DummyTokenParser('tag2'));

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:

$twig->addTokenParser(new DummyTokenParser('tag1'));
$twig->addTokenParser(new DummyTokenParser('tag2'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文