Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with showing images on list #1075

Closed
fourroses666 opened this issue Apr 19, 2017 · 4 comments
Closed

Problem with showing images on list #1075

fourroses666 opened this issue Apr 19, 2017 · 4 comments
Labels

Comments

@fourroses666
Copy link

fourroses666 commented Apr 19, 2017

I have an onepage site. The manager works fine, but showing the uploaded images on the front page gives an error.

My onepage.yaml (see .afb)

        tab3:
          type: tab
          title: Diensten

          fields:
            header.diensten:
              name: diensten
              type: list
              label: Diensten blokken
              style: vertical

              fields:
                .kop:
                  label: Kop
                  type: text
                .afb:
                  label: Afbeelding
                  type: file
                  destination: 'self@'
                  multiple: false
                  accept:
                    - image/*

So I have the option to upload an image:
list

This all works fine.

Then in my onepage.html.twig

        <div class="d-blokken respons">

            {% for diensten in page.header.diensten %}

                <div class="item">
                  <img src="{{ diensten.afb }}" alt="" />
                  <h4>{{ diensten.kop }}</h4>
                </div>

            {% endfor %}
     

          <div class="clear"></div>
        </div>

The {{ diensten.kop }} works great.
It seems {{ diensten.afb }} gives an error.

"An exception has been thrown during the rendering of a template ("Array to string conversion")."

Do I need to add .media or some other way to "call" the image?

Just started experimenting with Grav. Does it need a partial?! Really have no idea.

@flaviocopes
Copy link
Contributor

As mentioned in Slack, diensten.afb is likely an array. You need to look in the page markdown header structure, and write the twig accordingly. You can see it in Expert mode in Admin.

If it's an array, you need to iterate on it with a for loop.

@fourroses666
Copy link
Author

fourroses666 commented Apr 19, 2017

Sorry but I don't understand.
I can't find any good examples how to do it correct.

On expert mode Frontmatter says:

diensten:
    -
        kop: Onderhoud
        afb:
            user/pages/03.test-2/README.jpg:
                name: README.jpg
                type: image/jpeg
                size: 95277
                path: user/pages/03.test-2/README.jpg
etc..

That looks oke to me.

@flaviocopes
Copy link
Contributor

diensten.afb is an array. You cannot print it with {{diensten.afb}}. Now that I see the structure, you can write {{(diensten.afb|first).path}} to get the file path.

@fourroses666
Copy link
Author

Thank you allot Flavio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants