我是新来的timber

问题描述 投票:0回答:2

{% block component DATA %}

include

中的语法看起来像这样:

{% include "comment.twig" with {comment:cmt} %}

可能也适用于块。试一试。


timber不需要您像某些框架那样明确地“注册”组件。取而代之的是,您只需要在文件夹中组织.twig文件(例如,视图/组件/),然后在模板中引用它们。
wordpress twig timber
2个回答
1
投票
/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或任何其他模板文件:

0
投票
    {% include 'components/video.twig' with { video_url: 'https://example.com/video.mp4', caption: 'My awesome video' } %}
  1. 您可以使用Include函数轻松地制作组合并在任何文件中重复使用。这对于编写可维护和清洁的代码非常有用。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.