首页 > 解决方案 > 我将如何扩展木材以能够将手柄用作包含中的参考?

问题描述

我们使用带有 twig 引擎的 fractal.js 来制作网站原型。Fractal.js 带来了一个方便的功能,可以在包含中使用句柄。

因此{% include 'templates/components/teaser/basicTeaser.twig' %},您可以只写而不是写{% include '@basicteaser' %}。请参阅:https ://fractal.build/guide/core-concepts/naming.html#referencing-other-items

当然,这依赖于独特的组件名称,无论如何我都很高兴拥有它。

有人能指出我如何延长木材或树枝以使用这种把手的正确方向吗?

非常感谢!

标签: wordpresstwigtimber

解决方案


Twig 已经提供了从一组目录而不是一个目录加载模板的选项。

$loader = new \Twig\Loader\FilesystemLoader([$templateDir1, $templateDir2]);

另外,在将加载器传递给环境对象之前,您可以为自定义命名空间添加路径,即:

$loader->addPath($templateDir, 'admin'); 

然后你可以像这样使用你的命名空间:

$twig->render('@admin/index.html', []);

https://twig.symfony.com/doc/3.x/api.html#built-in-loaders


推荐阅读