wordpress - 我将如何扩展木材以能够将手柄用作包含中的参考?
问题描述
我们使用带有 twig 引擎的 fractal.js 来制作网站原型。Fractal.js 带来了一个方便的功能,可以在包含中使用句柄。
因此{% include 'templates/components/teaser/basicTeaser.twig' %}
,您可以只写而不是写{% include '@basicteaser' %}
。请参阅:https ://fractal.build/guide/core-concepts/naming.html#referencing-other-items
当然,这依赖于独特的组件名称,无论如何我都很高兴拥有它。
有人能指出我如何延长木材或树枝以使用这种把手的正确方向吗?
非常感谢!
解决方案
Twig 已经提供了从一组目录而不是一个目录加载模板的选项。
$loader = new \Twig\Loader\FilesystemLoader([$templateDir1, $templateDir2]);
另外,在将加载器传递给环境对象之前,您可以为自定义命名空间添加路径,即:
$loader->addPath($templateDir, 'admin');
然后你可以像这样使用你的命名空间:
$twig->render('@admin/index.html', []);
推荐阅读
- powershell - Powershell检查变量是否为对象
- react-native-popup-menu - 在菜单打开时在 MenuOption 中动态设置文本子项
- regex - 如何在 Go 中进行可选的正则表达式匹配
- c# - 我想使用 .net framework 4.0 开发 BOX 应用程序
- visual-studio-code - 当我想定位'make'之前的下层文件夹时,如何设置'Task.json'?
- python - 通过唯一值熊猫数据框使用 3 列查找前 5 名
- python - 将数据帧解析为 Google API 时出错
- python - 计算 n 维实例之间的自定义距离
- ios - 有没有办法让某些代码在应用程序终止后继续运行?
- python - 如何将图像分配为从网络抓取中获取的变量?