[英]Not rendering block on diffrent server (ACF + Gutenberg + Timber)
[英]Timber + Gutenberg ACF Blocks doesnt rendering front end
这是我的 Class,它在木材站点 class 上扩展。
<?php
class EngineACF extends Timber\Site {
public function __construct() {
parent::__construct();
add_action( 'admin_head' , [$this, 'adminStyle']);
add_action( 'acf/init', [$this, 'acfBlocks'] );
}
/**
* Define Gutenberg Blocks
* @version 1.0
*/
public function acfBlocks()
{
if (!function_exists( 'acf_register_block' )) {
return;
}
$blocks = [
[
'name' => 'homepage-slider',
'title' => 'Homepage Slider'
]
];
foreach ($blocks as $perKey => $perBlock) {
acf_register_block(
[
'name' => data_get($perBlock, 'name'),
'title' => data_get($perBlock, 'title'),
'description' => data_get($perBlock, 'title'),
'render_callback' => [$this, 'renderAcfCallback'],
'category' => 'formatting',
'icon' => 'format-aside',
'keywords' => [str_replace(' ', ',', data_get($perBlock, 'name'))],
]
);
}
}
/**
* Render Dynamic Gutenberg block template
* @version 1.0
*/
public function renderAcfCallback( $block, $content = '', $is_preview = false ) {
$blockName = data_get($block, 'name');
$blockName = str_replace('acf/', '', $blockName);
$context = Timber::context();
$context['block'] = $block;
$context['fields'] = get_fields();
$context['is_preview'] = $is_preview;
Timber::render( 'blocks/'.$blockName.'-block.twig', $context );
}
}
我也有,blocks/homepage-slider-block.twig 文件。 在管理面板中,使用古腾堡编辑器一切正常。 但在前端,帖子内容无法正常工作/呈现。
有什么帮助吗? 谢谢。
output 像:
好的。 我刚刚发现问题出在哪里。 我使用的是 twig 中的post.post_content
变量。
显然那不是一个包含最终内容的变量。
供有类似问题的人将来参考:使用{{post.content}}
变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.