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.

Themes & Styling

Display images from FILE upload

Started by tradedemon 7 years ago · 1 replies · 481 views
7 years ago

Hi guys,

Had a look over the forums but none of the solutions I've seen seem to be working for me. I have the following in my blueprint which allows me to successfully upload an image.

YAML
header.yoyo.hero.image:
                    ordering@: 5
                    type: file
                    label: Media
                    destination: 'self@'
                    multiple: false
                    accept:
                      - image/*
                      - video/*

Within the twig template I can access it perfectly fine by filename e.g.

<img src="{{ page.media['illo-caterers-2x.png'].url }}"/>

I just can't figure out how to display the image by the blueprint variable name, I've tried the below and it gives me a null for the url.

{{ dump(page.media[yoyo.hero.image].url()) }}

7 years ago

ok so I got it working with this, however if someone can explain why I can't just do:

Doesn't Work

{{ page.header.yoyo.hero.image.url }}

Works

TWIG
        {% for key,val in page.header.yoyo.hero.image %}
            {% set myimagepath = '/' ~ val.path %}
            <img src="{{home_url}}{{myimagepath}}" class="hero-img" />
        {% endfor %}

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 224 2 months ago
Themes & Styling · by Ian, 2 months ago
3 118 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 481 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 72 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 152 3 months ago