# ACF-Composer Block Creation - Need Help with Fields

**URL:** https://discourse.roots.io/t/acf-composer-block-creation-need-help-with-fields/27196
**Category:** sage
**Tags:** acf-composer, sage10, acf
**Created:** 2024-05-25T06:25:44Z
**Posts:** 5

## Post 1 by @Tartamata — 2024-05-25T06:25:44Z

Hi everyone,

I’m working on creating blocks with ACF Composer and I have a couple of questions:

- I’m currently using the ACF GUI to define my block’s fields. Is this okay, or should I avoid it? Can I get rid of the `fields()` function entirely without causing issues?
- My block has two fields - Heading and Paragraph. How do I access these fields within the controller? Should I create individual functions for each field retrieval, like this:

```
...
    public function with()
    {
        return [
            'heading' => $this->heading(),
            'paragraph' => $this->paragraph(),
        ];
    }
...
    public function heading()
    {
        return get_field('heading');
    }

    public function paragraph()
    {
        return get_field('paragraph');
    }
...
```

Is there a more efficient or recommended way to handle this?

Thanks in advance for any help!

---

## Post 2 by @Log1x — 2024-05-25T07:34:03Z

I’ve never tried defining fields inside of the GUI for a block but I imagine it should be fine. You’ll have to keep the `fields()` method and have it return an empty array.

For the `get_field()` stuff, you can either put it in methods like you have in your example or just pass `get_field()` directly inside of `with()` like `'heading' => get_field('heading')`.

---

## Post 3 by @Tartamata — 2024-05-26T13:38:42Z

Thank you  
One last question, please :slight_smile: :  
Do we need to add a check (if-else) for every ACF field we include in a Laravel Blade view?

Example:

```
@if ($items)
@foreach ($items as $item)
<div>
  <div>
    <div>
      @if ($item['fieldOne'])
      <h2>{{ $item['fieldOne'] }}</h2>
      @endif
    </div>
    @if ($item['fieldTwo'])
    <p>{{ $item['fieldTwo'] }}</p>
    @endif
    @if ($item['fieldThree'])
    <p>{{ $item['fieldThree'] }}</p>
    @endif
  </div>
</div>
@endforeach
@endif
```

---

## Post 4 by @Log1x — 2024-05-26T21:24:00Z

If they don’t return a default value or you need to control wrapper markup, then what you’re doing probably makes sense. Otherwise, you can reach for coalescing operators.

---

## Post 5 by @Tartamata — 2024-05-27T05:16:52Z

Thank you very much Brandon
