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

Buildin staff page

Solved by Karmalakas View solution

Started by mmm 4 years ago · 5 replies · 533 views
4 years ago

Hi,
i just need to build a staff page. Each person has its own fields like name, surname, photo and so on. There is few people as staff, less than 10.
I wonder what's the best way to do it.
It seems flex objects are perfect for this, but seems just a bit overwhelming.
I just need to set in page content a list with fields like:

YAML
- name
- surname
- photo

- name
- surname
- photo

and so on
and then render it through my custom twig template. This seems to be the easiest way.

What do you think about?

4 years ago

If there's no page for each person and list will be available only on one page, then I would do just a simple array in page frontmatter (similar to your example) and access it in that custom template

👍 1
4 years ago

@Karmalakas:
I would do just a simple array in page frontmatter

I would do it that way, too. Another way is to create a modular page for each staff member. If there was a requirement for a page per staff member, I would do them as pages.

The best option also depends who is editing and what they are using (Admin UI or file editing).

It does seem like a great use case for Flex Objects but if it's any consolation, I still don't understand them enough to use them either. They are at least documented now. However I don't understand the documentation!

👍 1
4 years ago

You're both absolute right!
I tried the gallery recipe example and is much easy, but meta info does not show up.
My staff.md file:

YAML
---
- myphoto.jpg
- myphoto.jpg.meta.yaml
- myphoto2.jpg
- myphoto2.jpg.meta.yaml
---

# Our staff

## Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

my staff.html.twig template:

TWIG
{% block content %}
    <section id="staff">
        {{ page.content|raw }}

        <ul>
        {% for image in page.media.images %}
            <li>
                <img src="{{ image.url|raw }}" alt="staff photo" class="staff-photo">
                 <h4 class="staff-name">{{ image.meta.name }} {{image.meta.surname}}</h4>
                <i class="fa fa-plus-circle" aria-hidden="true"></i>
            </li>
        {% endfor %}
        </ul>
    </section>
{% endblock %}

and one of my myphoto.jpg.meta.yaml:

YAML
- name: jack
- surname: nicholson
- short_bio: Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

image is shown correctly, but meta infos doesn't

4 years ago Solution

Check here how media meta works. In your case I think you don't even need the frontmatter list of photos or meta files - Grav automatically finds media if it's in the same page folder. And in your template just use as you already have. You will need to fix meta file to:

YAML
name: jack
surname: nicholson
short_bio: Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
👍 1
4 years ago

doh!! putting as you said meta file works!!!!!
thanks all folks!!!

👍 1

Suggested topics

Topic Participants Replies Views Activity
General · by jean-louis67, 3 weeks ago
2 308 3 weeks ago
General · by Andy Miller, 3 weeks ago
0 310 3 weeks ago
General · by Veehem, 4 weeks ago
0 263 4 weeks ago
General · by milkboy, 4 weeks ago
0 264 4 weeks ago
General · by ian russell, 1 month ago
2 335 1 month ago