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

File field frontmatter format

Solved by Dimitri Longo View solution

Started by mikael 9 years ago · 2 replies · 811 views
9 years ago

Hi! So I made a custom blueprint in admin.

YAML
title: Gallery
form:
  fields:
    tabs:
      type: tabs
      active: 1

      fields:
        gallery:
          type: tab

          fields:
            header.gallery:
              name: gallery
              type: list
              style: vertical
              label: Gallery list
              collapsed: true
              fields:
                .tittel:
                  type: text
                  label: Title
                .method:
                  type: text
                  label: Method
                .date:
                  type: datetime
                  label: Date
                .upload:
                  type: file
                  name: image
                  label: Choose image
                  destination: 'self@'

Frontmatter output:

YAML
title: Gallery
gallery:
    -
        title: Stikket
        method: 'Pencil drawing'
        upload:
            user/pages/01.gallery/Stikket.jpg:
                name: Stikket.jpg
                type: image/jpeg
                size: 256487
                path: user/pages/01.gallery/Stikket.jpg
    -
        title: 'Fra jorda'
        method: Sketch
        upload:
            user/pages/01.gallery/frajorda.jpg:
                name: frajorda.jpg
                type: image/jpeg
                size: 168208
                path: user/pages/01.gallery/frajorda.jpg

And this works greate! But, the output makes it so I can not access the image path to include in

TWIG
{% for image in page.header.gallery %}
    <img src="{{ image.upload.path }}"></img>
{% endfor %}

because the frontmatter header under upload becomes a unique name:

TXT
user/pages/01.gallery/frajorda.jpg:

I search and found alot of the same and similar problems, but it still is not a solution for this problem.
If I have to add a meta file for each image it would have to be automatically created when the image is uploaded since this site is used by someone who needs it to be as simple as possible.

Thanks!

9 years ago Solution

quick workaround, not tested

TWIG
{% for image in page.header.gallery %}
  {% for thumb in image.upload %}
    <img src="{{ page.media[thumb.name].url }}"></img>
  {% endfor %}
{% endfor %}
👍 1
9 years ago

Works very well! Thank you!

If there is someone who knows how to change the file frontmatter header too that would be great, even if it does not matter in this project I am sure it matters in others.

Thanks:)

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1135 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 132 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 108 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 127 7 months ago