What is the best solution for record content text for dynamic pages (doesn't exist in folders)


I have some dynamic pages generated through slug url (/city-[a-z]+) , then I call an API for retrieve content to this ID (somes real estate ads). I would like add specific text for each page but I don’t know what is the best solution for that.

Some ideas :

  • Create a specific Mysql tabe for record text for each cities, but I think it is not optimal.
  • Create content.md for each cities, but I don’t know where to save them and how. (And is it efficient to generate hundreds of files ?)

Thank you for replies.

I would avoid MySQL personally. There’s an SQLite plugin that will let you SELECT from a table. You can then use various plugins to present the tabular output.

If you’re really just talking about short chunks of text, you can also create a simple JSON or YAML file that contains the data and use the Import plugin to pull them into a page.

Thank you for answering.

I am a developer, I made the following code for create and read the good file for every pages.

It works, but I do not find it very clean, and quite rigid.
And I do not exploit the power of GRAV enough, but I block.
Impossible in my current knowledge to do anything more integrated into the GRAV ecosystem.

        $path = $this->slugify($uri->path());

        $file = $this->grav['page']->path() . '/_contents/' . $path . '.md';
        if (file_exists($file)) {
            $content = file_get_contents($file);
        } else {            

            if (!is_dir(dirname($file))) {                

            $path = $this->slugify($uri->path());
            $file = $this->grav['page']->path() . '/_contents/' . $path . '.md';
            $texte = 'blablablaba spin';            

            file_put_contents($file, $texte);
            $content = file_get_contents($file);