Exclude a field from the KirbyBuilder loop

Hello, I’m strating to use TimOetting builder. I’m using this generic loop for calling the fields. And I want to exlude the “quote” field from the output. I’ve got the intuition I should do something with ->not('quote') but lacking the savoir-faire to know where… Can you help me? thank you

<?php
foreach($page->builder()->toBuilderBlocks() as $block):
  snippet('blocks/' . $block->_key(), array('data' => $block));
endforeach;
?>

my yml looks like this
fields:
builder:
label: Page Builder
type: builder
columns: 1
fieldsets:
quote: blocks/quote
text: blocks/text
events: blocks/events

You could try something like this. Maybe it needs an underscore, depending how the fieldset is stored in content, I’m not 100% sure:

foreach($page->builder()->toBuilderBlocks()->filterBy('fieldset', '!=', 'quote') as $block):

Thank for the answer, it’s not working or I cannot make it work. Should I include this line snippet('blocks/' . $block->_key(), array('data' => $block));, then it just reapeat the loop, otherwise nothing outputs…?

Could you please post what is stored in such a builder field? Haven’t used one in a while…

title: Default Page
preset: page
fields:
  subtitle:
    label: Sous-titre
    type: text

  builder:
    label: Page Builder
    type: builder
    columns: 1 # Optional. If set to 2 or more, the builder blocks will be placed in a grid.
    max: 10 # Optional. Limits the number of builder blocks that can be added.
    fieldsets:
      quote: 
        name: Quote # The name option is used as a label for the buttons to add new fieldsets. It is also used as a label in the header of the fieldset, if the label option is not set explicitly (see next line).
        label: Citation de {{auteur}}
        fields:
          citation:
            label: Citation
            type: textarea
          auteur:
            label: Auteur
            type: text
      text: blocks/text
      extratext: blocks/extratext
      events: blocks/events

That’s the yaml file, I wanted to see the result in the content file…

Title: Cours de groupe 

----

Subtitle: Prise de conscience 

----

Builder:

- 
  title: ""
  text: |
    Je donne des cours…
    
    Comment se déroule un cours de groupe?
    Si vous n’êtes jamais venu, venez essayer un cours gratuitement!
  fontfamily: ""
  fontsize: null
  _key: text
  _uid: text_1590743463601_509
- 
  citation: >
    Ne jamais commencer à arrêter, ne
    jamais arrêter de COMMENCER.
  auteur: Cheva Shelhav
  _key: quote
  _uid: quote_1590743428851_509
- 
  title: Some title
  text: Some text
  fontfamily: ""
  fontsize: null
  _key: text
  _uid: text_1590935573420_859

Ah, ok, it’s called _key, not fieldset, so try using that instead.

filterBy('_key', '!=', 'quote')

Thank you very much, it’s working fine!! :smiley:

One more question, with this filter operators method is it possible to exclude two fields from the loop? I try/error with , and []… thanks

filterBy('_key', 'not in', ['a', 'b'])
1 Like