我一直致力于开发我自己的主题,并且不得不使用我的 Laravel Sage 环境使用 ACF 制作一些自定义块。
我的目标是从转发器对象中检索文本列表。 (成功运行,但仍然显示错误)。
所以抛出该错误的代码如下:
page.blade.php:
@php
$tv_lists = [];
while (have_rows('tv_lists')) {
the_row();
$tv_lists[] = [
'tv_list' => get_sub_field('tv_list'),
];
}
@endphp
@if(get_field('tv_lists'))
<div class="tv-lists col-12 col-md-8 col-lg-9 block-image">
@foreach($tv_lists as $tv_list)
@if(!empty($tv_list['tv_list']))
<div class="tv-list quote-content">
<a class="tv-list-text">{{ $tv_list['tv_list'] }}</a>
</div>
@endif
@endforeach
</div>
@endif
然后page.php中负责创建repeater块的PHP代码如下:->addRepeater('tv_lists', [
'conditional_logic' => [[['field' => 'links_type', 'operator' => '==', 'value' => 'list']]],
'label' => 'TV Lists',
'layout' => 'block',
])
->addText('tv_list', [
'label' => 'TV List',
])
->endRepeater()
提前感谢所有花时间阅读本文的人。
最佳答案
您需要一个 if
while
之前的声明
所以你想做这样的事情。
@php
$tv_lists = [];
if (have_rows('tv_lists'){
while (have_rows('tv_lists')) {
the_row();
$tv_lists[] = [
'tv_list' => get_sub_field('tv_list'),
];
}
}
@endphp
关于php - 如何解决 PHP ACF 错误 : "Trying to access array offset on value of type bool"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63935579/