Yes sorry for the lake of information.
It is in a frontend template but I use a recursive function with an incrementation of a int variable so I store my subpages in an array using
$article = $page->children;
and call them using
$article[$i];
Here is an except of the code:
$parts = $page->children('template=parts');
foreach ($parts as $i => $part) {
?>
<section id="<?= $part->id ?>" class="part lvl2 <?php echo ($i%2 == 0 ? 'even' : 'odd'); ?>">
<h1><?= $title ?></h1>
<?php
$lvl = 3;
$i = 0;
recursionLvl3($lvl, $i, $part, $article, $permalink);
?>
</section>
<?php
}
?>
The recursive function:
function recursionLvl3($lvl, $i, $part, $article, $permalink){
echo '<section class="lvl3">
<article class="lvl4 '; echo ($permalink == $article[$i]->name ? (strlen($article[$i]->title) > 0 ? 'big"' : '') : '"'); echo ($article[$i]->name ? ' id="' . $article[$i]->name . '"' : '"'); echo'>';
createArticle($article[$i]);
echo ' </article>
</section> <!-- lvl3 -->';
$i++;
echo '<section class="lvl3">';
echo ' <section class="lvl4">';
echo ' <article class="lvl5 '; echo ($permalink == $article[$i]->name ? (strlen($article[$i]->title) > 0 ? 'big"' : '') : '"'); echo ($article[$i]->name ? ' id="' . $article[$i]->name . '"' : '"'); echo '>';
createArticle($article[$i]);
echo ' </article>';
echo ' </section> <!-- lvl4 -->';
$i++;
echo ' <section class="lvl4">';
$lvl++;
if ($lvl > 0 && $i < count($part->children)) {
recursionLvl3($lvl, $i, $part, $article, $permalink);
}
echo ' </section> <!-- lvl4 -->';
echo '</section> <!-- lvl3 -->';
}
and createArticle function:
function createArticle($el){
//
// $el->setOutputFormatting(false);
// $title = $el->title->getLanguageValue('default');
// $titleFR = ($el->title->getLanguageValue('fr') ? $el->title->getLanguageValue('fr') : $title);
// $titleNL = ($el->title->getLanguageValue('nl') ? $el->title->getLanguageValue('nl') : $title);
echo ' <div class="close closeArticle"><span>×</span></div>';
echo ($el->title ? '<h2>'. $el->title .'</h2>' : '');
echo ($el->sous_titre ? '<h3>'. $el->sous_titre .'</h3>' : '');
echo '<div class="dates">';
echo ($el->date_debut ? '<h4 class="dateDebut"><span></span> ' . $el->date_debut . ' </h4>' : '');
echo ($el->date_fin ? '<h4 class="dateFin"> <span> ⤑ </span> ' . $el->date_fin . '</h4><br>' : '');
echo ($el->vernissage ? '<h4 class="vernissage"> <span>vernissage : </span>' . $el->vernissage . '</h4>' : '');
echo '</div>';
echo ($el->images ? '<img src="' . $el->images->first()->url . '" alt="" />' : '' );
echo '<div class="content">';
echo ($el->contenu ? $el->contenu : '' );
echo '</div>';
echo ($el->en_savoir_plus ? '<p class="savoirPlus">' : '' );
echo ($el->en_savoir_plus ? '<a href="' . $el->en_savoir_plus . '" target="_blank">En savoir plus</a>' : '' );
echo ($el->en_savoir_plus ? '</p>' : '' );
}
The commented lines are those which cause an issue.
Thank you,
Étienne