DroidOS
DroidOS

Reputation: 8900

Grav CMS page names

I have been experimenting with Grav for a few days now and find it a real breath of fresh air for someone who has only ever used WordPress. However, there is one thing that bothers me. The folder structure driven flat file page hierarchy used by Grav can easily end up with a folder structure like the one below

01.home
 |
 --- default.en.md
     |
     01.sub-page-1
                 |
                  --- default.en.md
     |
     02.sub-page-2
                 |
                  --- default.en.md

There in lies the problem. I prefer to edit my markdown in Visual Studio Code via SFTP, not in the Grav Admin panel. However, that means that I can end up with multiple default.en.md files open at the same time and that is a disaster waiting to happen. Is it possible to rename the markdown files to something more logical?

Upvotes: 2

Views: 376

Answers (2)

Dan
Dan

Reputation: 493

The name of the markdown file specifies which template to use. So in your example, all the pages in each subfolder will use default.html.twig located in templates/THEME_IN_USE/ folder.

I presume you've downloaded the basic template from Grav's official page. In that case, the default template is Antimatter. You can see that in themes/anitmatter there's a file called default.html.twig, so this template is applied. However, if you would set the theme in user/config/system.yaml to let's say my-theme (instead of Antimatter), you could define your own default.html.twig (your own template).

So to answer your question, you could create your own template for each page, or better still a template for similar pages (like blog posts). You could end up with something like this then.

pages
  01.home
   |
   --- default.en.md
       |
       01.blog-post
                   |
                    --- blog.en.md
       |
       02.contact
                   |
                    --- contact.en.md
themes
  my-theme
   |
    ...

    templates
        --- default.html.twig
        --- blog.html.twig
        --- contact.html.twig

Upvotes: 1

Jacobm001
Jacobm001

Reputation: 4539

You can actually.

By default, grav pulls the template type from the markdown file's name. However, you can override this behavior by setting the template variable in your page's YAML header. So we could easily have something like:

01.home
 |
 --- homepage.en.md
     |
     01.sub-page-1
                 |
                  --- home.subpage1.en.md

If we simply have a header of

---
title: blah
template: default
...
---

Upvotes: 3

Related Questions