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 · 411 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 Thomas, 1 week ago
3 99 6 hours ago
Support · by Anna, 3 days ago
2 98 1 day ago
Support · by Justin Young, 1 day ago
1 65 1 day ago
Support · by Duc , 1 week ago
2 101 6 days ago
Support · by Colin Hume, 1 week ago
2 94 6 days ago