How to pass data from virtual pages to a snippet?

I follow this instructions:

It creates virtual pages to a page.

It works with a multipage website.
But I’m working on a One-pager.

As soon as I add a Model like this, the Website through an unexpected error.


class PagenamePage extends Page

    public function children()
        $csv      = csv($this->root() . '/animals.csv', ';');
        $children = array_map(function ($animal) {
            return [
                'slug'     => Str::slug($animal['Scientific Name']),
                'template' => 'animal',
                'model'    => 'animal',
                'num'      => 0,
                'content'  => [
                    'title'       => $animal['Scientific Name'],
                    'commonName'  => $animal['Common Name'],
                    'description' => $animal['Description'],
        }, $csv);

        return Pages::factory($children, $this);


How can I pass the virtual pages to the snippet of the page?

Kind regards

What does your loop look like?

You mean this?

or this?

What is $data supposed to be, I’m missing the template where this snippet is called.

And please don’t post code as screenshots, but as code. Thanks.


<!DOCTYPE html>
<html lang="de">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $site->title() ?></title>
    <?= css('assets/css/index.css') ?>
    <?= css('assets/css/gallery.css') ?>

    <!-- fancyapp stuff -->
    <script src=""></script>

    <link rel="stylesheet" href="" />
    <script src=""></script>

<h1><?= $page->title()  ?></h1>
<ul class="animals">
    <?php foreach ($page->children() as $animal): ?>
      <a href="<?= $animal->url() ?>">
        <?= $animal->title() ?>
    <?php endforeach ?>

    foreach($pages->listed() as $section) {
        snippet($section->uid(), ['data' => $section]);


It is the /models/offers.php file which breaks the code…

Shouldn’t the /models/offers.php create the virtual pages which then the /snippets/offers.php can call?
Oh I see there is a mistake in /snippets/offers.php in Line 2. It should be $data instead of $page. But $data does not work as well.

Ok, found it.
I had to rename the function in models/offer.php from “children” to “anyname” and then I can call that function in snippets/offers.php

But why did php not output a clear error saying “functionname already used” ? (I did turn on debug in config.php).

No, if you want these entries from the csv file to be children of the offers page, the method in the model must be called children() not anyname, that doesn’t make sense. The whole purpose of the model is to overwrite the children() method of the parent model/class.

But exactly, it must be $data->children(), not $page->children() because $page would refer to the calling page, i.e. home.

… but it only works that way. :thinking:

Well, in your last post you didn’t even tell us what the error and the stacktrace was, something like “it breaks” is not really that helpful.

There was only
(Debug Mode was turned on).

So it was also not very meaningful to me.
I’m sorry, I was not able to find out more details about the error.

That message doesn’t appear with debug mode on. What does your config file look like?

Is that correct?

return [
    'debug' => true

If that’s the only return statement, yes. If you have multiple, no.

It is the only return statement in /site/config/config.php at the moment.

Maybe I have to add something like <?php before?

I was just gonna ask, of course, every php file (with php code in it) needs a php tag. Or maybe I should have said, php code needs a php tag-

Then this is just wrong.


I’m sorry, but I will never understand why the documentation is so minimalistic.
For a beginner like me, every char and filepath is important to understand the big picture.

But thanks for your patience.
It helped me a little step forward :slight_smile: