Merging content sources
Combine virtual content with content from the file system
In this example, let us look at how we can combine "virtual" content with content from the file system.
We will extend the Content from a spreadsheet example with content we actually add in the content
folder, let's say because we want to add an image to each animal and some additional content.
To this end, we add new subpages to the /animals
parent page, using the same slugs that we generated in the animals.php
model.
Your content structure should then look something like this.
Make sure to prepend the folder number, because we also use the number in our model.
However, if we now try to fetch these newly added images in the animal.php
template, this will have no effect. We first have to extend our model.
First, we add a new subpages
method that creates a new Pages object from the page's inventory array:
This method will fetch all pages that actually exist in the filesystem.
Within the closure of the array_map
method, we now try to find a page with each slug:
In the return array, we add the files and additional content if the page exists:
And finally, we modify our subpage template to fetch the additonal content: