wordpress - 我将如何扩展木材以便能够使用 handle 作为包含中的引用?

标签 wordpress twig timber

我们使用 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', []);

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

关于wordpress - 我将如何扩展木材以便能够使用 handle 作为包含中的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59106303/

相关文章:

html - 根据学期计划设置 URL

wordpress - 撇号周围的空格

php - 你会如何用 Twig 制作一个两列的表?

symfony - 覆盖 Twig 模板中的小部件时直接访问表单字段的值

wordpress-theming - 我应该在单个 wordpress 模板中使用 $post = Timber::query_post() 还是 $post = new TimberPost() ?

css - 显示列表简码上的响应式 CSS

php - Symfony/ Twig : how to pass additional data to a form?

php - 为子类别使用不同的模板

wordpress - 如何获取自定义帖子类型存档页面的链接? [WordPress]