Anyone used Faker to generate dummy content for Kirby before?

If you’ve used Laravel before, you might be familiar with the Faker PHP library used in database seeding. It generates fake data and I’d like to use it with Kirby.

However, I’m not 100% how I should set it up. I made a quick Kirby plugin by pulling it in via Composer and requiring the autoloader, so I have access to the Faker class and methods like Faker\Factory::create() within Kirby, but I’m not sure where I should be using it.

Where should I actually create these pages? A controller, route, page method? I feel like there’s no place that makes to me to put this code.
Should I be creating virtual pages?
Should I create real pages and persist them in the /content folder?

It’s like a mix of development and testing at the same time.

Any ideas are welcome. Thanks!

I think you have three options:

  • create those pages from a template
  • create them in a route
  • use a PHP script that you put e.g. in the root of the project

Virtual or real pages: That depends on the purpose. It’s probably easier to set them up as real pages.

You could use the spread sheet virtual page guide in the in the cookbook. If you all need is “stuff”… you can just clone rows in the spread sheet easy enough and quickly generate lots pages. You might be able to randmise the page title with an Excel formula/function.

@jimbobrjames Why would you create a spreadsheet as an intermediary when the data can be generated on the fly from the Faker library? That seems unnecessary to me…

Well, i just thought generating alot of fake data was the desired end result, wether thats Faker or otherwise. Im not really familiar with Faker, I just understood it was for generating random fake data.

Exactly, then you can either create pages from that data directly, or create virtual pages. But creating an additional storage is not needed.

I think i was aiming at a simple spreadsheet might be enough, instead of faker. But i understand what you mean.

There are different ways to generate dummy data (I’ve used a resource I can’t remember at the moment in the past), but I quite like the idea of using Faker.