include
中的语法看起来像这样:
{% include "comment.twig" with {comment:cmt} %}
可能也适用于块。试一试。
timber不需要您像某些框架那样明确地“注册”组件。取而代之的是,您只需要在文件夹中组织.twig文件(例如,视图/组件/),然后在模板中引用它们。/wp-content/themes/your-theme
├── views/
│ ├── components/
│ │ ├── video.twig
│ │ ├── button.twig
│ │ ├── card.twig
│ ├── page.twig
│ ├── single.twig
├── functions.php
├── index.php
视频的示例。Twig组件:
<div class="video-wrapper">
<video controls>
<source src="{{ video_url }}" type="video/mp4">
Your browser does not support the video tag.
</video>
{% if caption %}
<p class="video-caption">{{ caption }}</p>
{% endif %}
</div>
NOW,在您的页面中。twig或任何其他模板文件:
{% include 'components/video.twig' with { video_url: 'https://example.com/video.mp4', caption: 'My awesome video' } %}