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

Filepicker Image does not print to page

Solved by Eero View solution

Started by Eero 6 years ago · 1 replies · 504 views
6 years ago

Hi guys,

I just started using Grav a week ago. I can't seem to be able to get a different images showing for my feature sections. I have a modular page and I'm able to get the "first" image printed from the Page media since I copied this from the Quark template:
{% set feature_image = page.header.feature_image ? page.media[page.header.feature_image] : page.media.images|first %}

And used this in the html:

TWIG
{% if feature.feature_image %}
     {{ feature_image.cropResize(300,200).html }}
{% endif %}

Here's also the .yml:

YAML
.feature_image:
   label: Feature Image
   type: filepicker
   folder: 'self@'
   preview_images: true

I tried to modify the bit I copied from the Quark template but I usually just end up getting some error as a result or it doesn't print to the page at all..

Any tips on how to fix this bit or just do the same thing some other way? Thanks.

last edited 03/08/20 by Eero
6 years ago Solution

So ok, after some playing around, it was quite simple in the end.

YAML
header.features:
   name: features
   type: list
   label: Features
   fields:
      .feature_image:
          label: Feature Image
          type: filepicker
          folder: '@self'
          preview_images: true
TWIG
{% for feature in page.header.features %}
   <div class="feature-column {{ columns }}">
         {% set feature_image = page.media.images[feature.feature_image] %}
         {{ feature_image.html }}
   </div>
{% endfor %}

Suggested topics

Topic Participants Replies Views Activity
Support · by Paul Hodges, 4 weeks ago
19 487 6 days ago
Support · by Lauw, 7 days ago
2 104 7 days ago
Support · by Anna, 3 weeks ago
4 426 1 week ago
Support · by gtx, 4 weeks ago
4 377 3 weeks ago
Support · by Anna, 1 month ago
9 484 4 weeks ago