Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

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

Started by NicolasG 🇫🇷 8 years ago · 2 replies · 481 views
8 years ago

Hello,

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.

8 years ago

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.

8 years ago

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.

PHP
        $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))) {                
                mkdir(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);
        }

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 64 18 hours ago
Support · by Anna, 3 days ago
2 68 21 hours ago
Support · by Justin Young, 21 hours ago
1 35 21 hours ago
Support · by Duc , 1 week ago
2 71 6 days ago
Support · by Colin Hume, 1 week ago
2 63 6 days ago