Hello, this time I try to have content from builder going in a column or the other.
I would like the toggle choixcolonne to be in each section of the builder so that the user can choose where the content go.
I try with different combination, I ask for help with this:
<?php if ($block->choixcolonne()->toBool()): ?>
<?php
foreach($page->builder()->toBuilderBlocks() as $block):
snippet('blocks/' . $block->_key(), array('data' => $block));
endforeach;
?>
<?php endif ?>
My blueprint look something like this
fields:
builder:
type: builder
fieldsets:
extratext: blocks/extratext
and
name: Extratexte
tabs:
content:
fields:
choixcolonne:
type: toggle
default: false
I get the feedback I do it wrong, I get the feeling I might do it differently in my approach, (I plan to have a snippet for the toggle to repeat in other template blueprint), can you help with this? Thank you
You are calling the block before this variable is defined inside the loop…
Sure, then should I do, but it is not working…?
<?php foreach ($page->builder()->toBuilderBlocks() as $block): ?>
<?php if ($block->choixcolonne()->toBool()): ?>
<?php
foreach($page->builder()->toBuilderBlocks() as $block):
snippet('blocks/' . $block->_key(), array('data' => $block));
endforeach; ?>
<?php endif ?>
<?php endforeach ?>
I’m not quite sure what you want to achieve here? What do you want to happen when the toggle is set to true?
Also, could you please post the complete blueprint setup for the builder block.
I’ve got two columns, and I want the toggle on each blocks so that the user can choose if the block goes on column 1 or 2. The toggle option made make more sense to me than having one separate builder for each column.
(at this time I just put it on extratext to try)
title: Default Page
preset: page
fields:
contenu:
label: Contenu principal
type: headline
builder:
label: Éléments
type: builder
fieldsets:
quote: blocks/quote
text: blocks/text
extratext: blocks/extratext
events: blocks/events
and the extratext block is
name: Extratexte
label: {{title}} (extratexte)
tabs:
content:
label: Contenu
fields:
choixcolonne:
name: Colonne de droite
label: Section de page de droite
type: toggle
default: false
So basically that means that you have to filter your blocks by the value of the choixcolonne field? So that you can put those with true in one column, and the others in the second column?
Not tested:
$columnOneBlocks = $page->builder()->toBuilderBlocks()->filter(function($block) {
return $block->choixcolonne()->toBool() === true;
});
foreach ($columnOneBlocks as $block) {
// do stuff
}
Thanks. I will try to build from here… tommorow is another day