我在Wordpress网站上使用木材,我正在尝试开始建造古腾堡积木。块在后端编辑器中工作,但我无法让它们在模板中工作。事实上,当我尝试使用{{post.content}}时,内容框中的任何内容都不会打印到屏幕上,因为它只返回null。
如何获取帖子。返回内容的内容?
WP-5.8木材1.18.0
模板块测试。php
<?php
/* Template Name: block test */
$context = Timber::get_context();
Timber::render( \'template-block-test.twig\', $context );
模板块测试。细枝
{% extends \'base.twig\' %}
{% block content %}
<h1>Header to test file</h1>
{{post.content}} //returns null
<pre>
{{dump()}}
</pre>
{% endblock %}
功能。php
add_action( \'acf/init\', \'acf_forty_it_block\', 9 );
add_action( \'acf/init\', \'acf_forty_it_block_settings\', 10 );
function acf_forty_it_block() {
// Check function exists.
if( function_exists( \'acf_register_block_type\' ) ) {
// register a testimonial block.
acf_register_block_type( array(
\'name\' => \'fortyblock\',
\'title\' => __(\'Forty\'),
\'description\' => __(\'Forty does a great job at been 60/40\'),
\'render_callback\' => \'my_acf_block_render_callback\',
\'category\' => \'design\',
\'icon\' => \'format-gallery\',
\'keywords\' => array( \'test\', \'forty\', ),
) );
}
}
function my_acf_block_render_callback( $block, $content = \'\', $is_preview = false ) {
$context = Timber::context();
$context[\'block\'] = $block;
$forty = array(
\'top_header\' => get_field(\'forty_top_header\'),
\'text\' => get_field(\'forty_text\'),
\'list_content\' => get_field(\'forty_list_content\'),
\'image\' => get_field(\'forty_image\'),
\'color\' => get_field(\'forty_color\'),
);
$context[\'forty\'] = $sixtyForty;
$context[\'is_preview\'] = $is_preview;
// Render the block.
Timber::render( \'blocks/forty.twig\', $context );
}