我们使用 fractal.js 和 twig 引擎来制作网站原型(prototype)。 Fractal.js 带来了一个方便的功能,可以在包含中使用句柄。
因此,您不必编写 {% include 'templates/components/teaser/basicTeaser.twig' %}
,只需编写 {% include '@basicteaser' %}
>。请参阅:https://fractal.build/guide/core-concepts/naming.html#referencing-other-items
当然,这依赖于独特的组件名称,无论如何我很高兴拥有它。
有人能给我指出如何延伸木材或 Twig 以使用此类 handle 的正确方向吗?
非常感谢!
最佳答案
Twig 已经提供了从一组目录而不是一个目录加载模板的选项。
$loader = new \Twig\Loader\FilesystemLoader([$templateDir1, $templateDir2]);
另外,在将加载程序传递给环境对象之前,您可以添加自定义命名空间的路径,即:
$loader->addPath($templateDir, 'admin');
然后你可以像这样使用你的命名空间:
$twig->render('@admin/index.html', []);
关于wordpress - 我将如何扩展木材以便能够使用 handle 作为包含中的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59106303/