【发布时间】:2021-05-31 10:34:56
【问题描述】:
我正在尝试使用 Timber/Twig 在 WordPress 中创建自定义页面模板。
我使用了以下代码,但不明白为什么它不起作用。 木材文档没有提供具体示例。
我有一个名为 template-form-template.php 的文件,用于多个表单页面。 我更喜欢在 admin 中选择模板,而不是为每个页面 slug 创建一个 page-...twig。
<?php
/**
* Template Name: Form Template
* Description: Use this template for custom forms.
*/
$context = Timber::context();
$context['post'] = new Timber\Post();
Timber::render( 'page-form.twig', $context );
?>
模板名称按预期显示在 WordPress 管理员中。 但是,没有调用 page-form.twig。 我正在测试的页面中有一个简码,它显示为原始简码,这意味着页面内容正在显示,但没有树枝格式。
page-form.twig 内容为:
{% extends "base.twig" %}
{% block content %}
<div class="content-wrapper">
<article class="post-type-{{post.post_type}}" id="post-{{post.ID}}">
<section class="article-content">
<h1 class="article-h1">page.twig{{post.title}}Foooo</h1>
<div class="article-body">
{{post.content}}
</div>
</section>
</article>
</div>
<!-- /content-wrapper -->
{% endblock %}
【问题讨论】:
标签: wordpress templates twig timber