Hi,
I’m trying to filter a list of entries with three different states (visible, auto, spoiler) and recombine them into two lists. On list should contain all visible plus n auto entries and the other list should contain all spoiler plus the remaining auto entries. But I made some mistake. To reproduce the problem pleas try the following.
Download the starter kit (2.2.3) and add these two files
<!-- templates/test.php -->
<?php snippet('header') ?>
<main class="main" role="main">
<div class="text">
<h1><?php echo $page->title()->html() ?></h1>
<?php
$n = 10;
$entries = $page->entries()->toStructure();
$visibleEntries = $entries
->filterBy('visibility', 'visible')
->merge($entries->filterBy('visibility', 'auto')->limit($n))
->sortBy('sort');
$spoilerEntries = $entries
->filterBy('visibility', 'spoiler')
->merge($entries->filterBy('visibility', 'auto')->offset($n))
->sortBy('sort');
?>
<h2>Visible Entries</h2>
<p>
This list should contain <emph>all</emph> entries with
<code>visibility: visible</code> and the first <code>$n</code>
elements with <code>visibility: auto</code>.
</p>
<ul>
<?php foreach ($visibleEntries as $e) : ?>
<li><?php echo $e->text() ?></li>
<?php endforeach ?>
</ul>
<h2>Spoiler Entries</h2>
<p>
This list should contain <emph>all</emph> entries with
<code>visibility: spoiler</code> and the elements with
<code>visibility: auto</code> exept the first <code>$n</code>.
</p>
<ul>
<?php foreach ($spoilerEntries as $e) : ?>
<li><?php echo $e->text() ?></li>
<?php endforeach ?>
</ul>
<h2>All Entries</h2>
<p>
This list should contain <emph>all</emph> entries.
</p>
<ul>
<?php foreach ($entries->sortBy('sort') as $e) : ?>
<li><?php echo $e->text() ?></li>
<?php endforeach ?>
</ul>
</div>
</main>
<?php snippet('footer') ?>
# content/test/test.txt
Title: TEST
----
Entries:
-
sort: 16
text: 16 (visible)
visibility: visible
-
sort: 15
text: 15 (visible)
visibility: visible
-
sort: 14
text: 14 (spoiler)
visibility: spoiler
-
sort: 13
text: 13 (auto)
visibility: auto
-
sort: 12
text: 12 (auto)
visibility: auto
-
sort: 11
text: 11 (auto)
visibility: auto
-
sort: 10
text: 10 (spoiler)
visibility: spoiler
-
sort: 9
text: 9 (spoiler)
visibility: spoiler
-
sort: 8
text: 8 (auto)
visibility: auto
-
sort: 7
text: 7 (auto)
visibility: auto
-
sort: 6
text: 6 (auto)
visibility: auto
-
sort: 5
text: 5 (auto)
visibility: auto
-
sort: 4
text: 4 (auto)
visibility: auto
-
sort: 3
text: 3 (auto)
visibility: auto
-
sort: 2
text: 2 (auto)
visibility: auto
-
sort: 1
text: 1 (auto)
visibility: auto
and then open the preview of test. As you will see the first list contains $n element, while it should contain $n plus # of visible = 7 entries. What am I doing wrong?
Thanks in advance ![]()
Tobi
