In this example we are going to read a list of (dummy) animals from a CSV file and create virtual pages for each animal.
Let's create an animals folder for our site, which is used as the parent for all animal subpages.
We can put the animals.csv directly inside this folder to make it nice and clean to read data from that file. You could even provide an uploader for this in the panel later, so your content editors can update the csv file whenever they have a fresh export with updated data.
To convert the CSV from the file to a PHP array we are going to use a little
csv() helper function. This function is stored in a small plugin. It takes the absolute path to the csv file and returns a nice and clean array.
We are using a new page model for the animals page, which will read from the csv and create a virtual child page for each animal on the fly.
With the new page model, we can now render all animals in our
animals.php template as if they were regular Kirby pages.
Each animal will automatically get its own subpage. Routing will work out of the box and you can create an
animal.php template to render each individual animal.