Hello,
I created a substructure in a structure.
I have a difficulty to recover the data of the under structure because they are put in array.
Here is my code for better understanding:
The blueprint
listing:
label: Contenu(s) texte(s)
type: structure
fields:
parcourstitle:
label: Titre
type: text
width: 1/1
parcourstext:
label: Texte
type: textarea
size: small
width: 1/1
listing2:
label: Sous-texte(s)
type: structure
fields:
listing2parcourstitle:
label: Titre
type: text
width: 1/1
listing2parcourstext:
label: Texte
type: textarea
size: small
width: 1/1
Code
<?php
$items = $page->listing()->toStructure();
foreach($items as $item): ?>
<section>
<div class="container bg-white pt-2 px-5">
<div class="row">
<div class="col-12 mb-3">
<h2>
<?php if($item->parcourstitle()->isNotEmpty()):?>
<?= $item->parcourstitle() ?>
<?php else: ?>
Texte non renseigné
<?php endif ?>
</h2>
<?php if($item->parcourstext()->isNotEmpty()):?>
<?= $item->parcourstext()->kirbytext() ?>
<?php else: ?>
<p>Texte non renseigné.</p>
<?php endif ?>
<?php
// Sous listing
var_dump($item->listing2());
?>
data: <?= $item ?>
<?php //endforeach ?>
</div>
</div>
</div>
</section>
<?php endforeach ?>
The result of the var_dump which finds the data fine for me.
<p>text un</p>
object(Kirby\Cms\Field)#542 (1) {
["listing2"]=>
array(5) {
[0]=>
array(2) {
["listing2parcourstitle"]=>
string(28) "Camaraderie et convivialité"
["listing2parcourstext"]=>
string(6) "A TEXT"
}
[1]=>
array(2) {
["listing2parcourstitle"]=>
string(16) "Rouler en groupe"
["listing2parcourstext"]=>
string(7) "B TEXTE"
}
[2]=>
array(2) {
["listing2parcourstitle"]=>
string(28) "Participer aux séjours club"
["listing2parcourstext"]=>
string(0) ""
}
[3]=>
array(2) {
["listing2parcourstitle"]=>
string(29) "Conseils santé et sécurité"
["listing2parcourstext"]=>
string(0) ""
}
[4]=>
array(2) {
["listing2parcourstitle"]=>
string(18) "Atelier mécanique"
["listing2parcourstext"]=>
string(0) ""
}
}
}
data: 0
....
<p>text deux</p>
object(Kirby\Cms\Field)#546 (1) {
["listing2"]=>
array(3) {
[0]=>
array(2) {
["listing2parcourstitle"]=>
string(10) "Assurances"
["listing2parcourstext"]=>
string(16) "assurances texte"
}
[1]=>
array(2) {
["listing2parcourstitle"]=>
string(14) "Club avantages"
["listing2parcourstext"]=>
string(19) "Club avantages text"
}
[2]=>
array(2) {
["listing2parcourstitle"]=>
string(40) "Votre cotisation déductible des impôts"
["listing2parcourstext"]=>
string(44) "Votre cotisation déductible des impôts tex"
}
}
}
data: 1
Thanks for your help