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

Getting an image not in a page

Started by Muut Archive 10 years ago · 2 replies · 426 views
10 years ago

I have an image saved and set in my site yaml config file:

YAML
gv:
  map_image:
    user/themes/site/assets/map.jpg:
      name: map.jpg
      type: image/jpeg
      size: 123514
      path: user/themes/site/assets/map.jpg

The image exists in the correct directory but I can't get it to display in the page:

TWIG
{% for item in site.gv.map_image %}
<img src="{{ page.media[item.name].cropZoom(1200,350).quality(100).url() }}" alt="">
{% endfor %}

If I run a test like this:

TWIG
{% for item in site.gv.map_image %}
{{ item.name }} 
{% endfor %}

It outputs the name fine and any other var, it's just not outputting the image in Grav's image function thing. Is that because it's not in the page and so the 'page.media' function isn't working? I don't really understand how it works...

10 years ago

Use page.media for the page's media (contained in the page's folder. In your case the image is in another folder, so you can't use that syntax.

Use this instead.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1338 9 years ago
Archive · by Muut Archive, 9 years ago
2 927 9 years ago
Archive · by Muut Archive, 9 years ago
2 4056 9 years ago
Archive · by Muut Archive, 9 years ago
1 2941 9 years ago
Archive · by Muut Archive, 9 years ago
3 1112 9 years ago