Use the "Page Builder" fields twice in the same page?

Hello,

I would like to use the “Page Builder” from @timoetting several time in the same page.
It seems impossible.

I tried two approaches in the blueprint:

1- Call two builder fields “builderA” & “builderB”. I see two builder in the panel but can’t get data from the two builders in the front end:

title: Page
pages: true
files: true
fields:
  builderA:
    label: Section A
    type: builder
    fieldsets:
      texta:
        label: Text A
        snippet: sections/texta/texta
        fields:
          text:
            label: text a
            type: text
  builderB:
    label: Section B
    type: builder
    fieldsets:
      textb:
        label: Text B
        snippet: sections/textb/textb
        fields:
          text:
            label: text b
            type: text

2- Call the two fields “builder”. I see only one builder in the panel:

title: Page
pages: true
files: true
fields:
  builder:
    label: Section A
    type: builder
    fieldsets:
      texta:
        label: Text A
        snippet: sections/texta/texta
        fields:
          text:
            label: text a
            type: text
  builder:
    label: Section B
    type: builder
    fieldsets:
      textb:
        label: Text B
        snippet: sections/textb/textb
        fields:
          text:
            label: text b
            type: text

Is there a way to work with several “Page Builder” in the same blueprint?

Thx

Could you please use three “backticks” (the `) before and after your code so it is readable?
Let’s try to fix your code once that’s done :wink:

You’re right sorry, done :wink:

That looks better :slight_smile:
Can you explain what you mean by

I see two builder in the panel but can’t get data from the two builders in the front end

What code are you using in your template?
Are you getting any errors?
Is debugging on in your site config?

You cannot have two fields with the same name in one blueprint, that’s why your second example does not work.

Could you please also post the code that fetches the content from those fields?

My blueprint = “home.yml” (code above)
kirby/site/blueprint/

My template = "home.php"
kirby/site/templates/

<?php snippet('header') ?>

<h1><?php echo $page->title()->html() ?></h1>

<?php foreach($page->builder()->toStructure() as $section): ?>
  <?php snippet('sections/texta/' . $section->_fieldset(), array('data' => $section)) ?>
<?php endforeach ?>

<?php foreach($page->builder()->toStructure() as $section): ?>
  <?php snippet('sections/textb/' . $section->_fieldset(), array('data' => $section)) ?>
<?php endforeach ?>

<?php snippet('footer') ?>

My snippets = “texta.php” and “textb.php”

kirby/site/snippets/sections/texta/texta.php

<?php
echo $data->text()
?>

kirby/site/snippets/sections/textb/textb.php

<?php
echo $data->text()
?>

Debug option to true > no errors

Is the blueprint exactly as given above? Because you use textb twice …

It’s a typo, I have fixed the code.

You’re not calling your builder fields here.
First change the name of your builderfields to buildera and builderb. It’s not good to use caps in field names as it can create unwanted issues.

Next, change your template to the following:

<?php snippet('header') ?>

<h1><?php echo $page->title()->html() ?></h1>

<?php foreach($page->buildera()->toStructure() as $section): ?>
  <?php snippet('sections/texta/' . $section->_fieldset(), array('data' => $section)) ?>
<?php endforeach ?>

<?php foreach($page->builderb()->toStructure() as $section): ?>
  <?php snippet('sections/textb/' . $section->_fieldset(), array('data' => $section)) ?>
<?php endforeach ?>

<?php snippet('footer') ?>

Tell us how it works !

1 Like

Yes it works \0/

Thanks very much @Thiousi and @texnixe for your help :slight_smile:

No worries!
By the way, you don’t need to use texta and textb in your two separate builder fields I think. They can use the exact same field names as they are in separate structures.
You can verify that I’m not mistaken here.

Effectively, this blueprint works as well:

title: Page
pages: true
files: true
fields:
  buildera:
    label: Section A
    type: builder
    fieldsets:
      text:
        label: Text A
        snippet: sections/texta/text
        fields:
          text:
            label: text a
            type: text
  builderb:
    label: Section B
    type: builder
    fieldsets:
      text:
        label: Text B
        snippet: sections/textb/text
        fields:
          text:
            label: text b
            type: text
1 Like