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.

Forms & Blueprints

List fields in admin panel

Solved by pamtbaau View solution

Started by Pavel 11 months ago · 3 replies · 72 views
11 months ago

I’m new to Grav (even though I’ve been discretely programming websites for many years). I currently have a problem with Grav that I cannot solve:

I want to have a list for a specific page in the admin panel—instead of the editor or in addition to the editor.
My blueprint works, but the data I enter into the list isn’t saved.

Here is a simplified example: its blueprint:

YAML
title: Termine
extends@:
  type: default
form:
  fields:
    tabs:
      fields:
        content:
          fields:
            replace@: true
            content: 
               type: list
               label: Terminliste
               fields:
                  zeit:
                     type: text
                     label: Zeit
                  bezeichnung:
                     type: text
                     label: Text
                  zusatz:
                     type: text
                     label: Zusatz

The admin panel with example entries:
panel_liste|690x409

After “Save,” the panel closes; the data isn’t saved and isn’t included in the list when the panel is reopened. And not in /user/pages/termine.md:

YAML
---
title: Termine
---

For comparison: Instead of the list, I used a simple text field:

YAML
title: Termine
extends@:
  type: default
form:
  fields:
    tabs:
      fields:
        content:
          fields:
            replace@: true
            content: 
               type: text
               label: Termin

the admin panel: Sorry, I am not allowed to send a second screenshot here. But I promise, it works fine.

After saving, the panel remains open, the data is saved; in /user/pages/termine.md it says:

YAML
---
title: Termine
---

heute: alle kommen

What do I need to do to make this work with a list?

11 months ago Solution

@paulchen, Grav expects a page file (*.md) to consist of frontmatter (formatted using yaml, which will be translated into object|null) and content (string|null). The content could contain Markdown, HTML, or plain text.

Grav doesn't expect anything else as content and will probably ignore anything else than string|null.

If you want to save a structure, you should use the frontmatte, using something like:

YAML
fields:
  header.termine:
    type: list
    ... etc.
11 months ago

im not sure if its right word but you didnt make fields under list child of the list field so they will connect to list like content.zeit
example:

YAML
 content: 
               type: list
               label: Terminliste
               fields:
                  .zeit:
                     type: text
                     label: Zeit

spaces are probably wrong but you can make them 2spaces for each. also i want to point that i added "." before the fields name to make it connected to its parent field.
i also had hard time while learning flex, i asked a lot about it and got a lot help but still there are so much to know because there are so much we can do with it. looking json file that flex creates to save data is really helpful for me.

10 months ago

Thank you for your quick answer.
It is exactly what I needed. I added a period at the beginning of the subfield names, and it works.
For completeness, here is my now functioning blueprint file termine.yaml:

YAML
title: Termine
extends@:
  type: default
form:
  fields:
    tabs:
      fields:
        content:
          fields:
             header.termine:
               type: list
               label: Terminliste
               fields:
                  .zeit:
                     type: datetime
                     label: "Wann:"
                  .titel:
                     type: text
                     label: "Wo:"
                  .zusatz:
                     type: text
                     label: "Was noch:"
                  .verweis:
                     type: url
                     label: "Siehe auch:"

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1133 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 60 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 131 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 107 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 125 7 months ago