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

Advice with a database-y problem

Started by Muut Archive 10 years ago · 2 replies · 343 views
10 years ago

Hello all! I'm working on a site right now and I need something that I think is typically database-y. I need a list of staff. On one screen I need a list of these staff sorted one way with 3 columns in the table. On another page in another part of the system I need the same data sorted a different way with 5 different columns of data. On another page I need a subset of the data with 4 completely different columns of data.

The problem is, as soon as the client changes staff, we're going to need to go through the site and replace all these hard-coded occurrences.

So what's the better approach? I understand that I could create a folder called staff and then create sub-folder / template pairs for each staff member. But that's not really an optimal way to do it for me. If forced, that's what I'll do.

Yes, I could use a database, but I'm trying to get away from that. Is there a simple, flat-file approach to my problem that I'm overlooking?

Any suggestions would be appreciated.

10 years ago

You could list the staff in site.yaml with a structure similar to

YAML
staff:
    - 
        name: Tom
        occupation: whatever
        description: xxx
        another_field: yyy
    - 
        name: Tim
        occupation: whatever else
        description: xxx
        another_field: yyy

and in your different pages, reference this data via twig, for example:

TWIG
{% for member in site.staff %} 
    {{ member.name }}
    {{ member.description }}
{% endfor %}

You can also then allow the staff to be edited from the admin

10 years ago

Flavioscopes: That's awesome! I had no idea I could do that. And it is a huge bonus that the client can maintain this table themselves via the admin. Superb! Thanks so much.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2955 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago