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

Images are not caching

Started by Muut Archive 10 years ago · 5 replies · 531 views
10 years ago

Hello everyone,

I am working on a page where I took the features.html.twig template of the antimatter theme and modified it so I can put my own pictures in the icon portion:

TWIG
       {% if current.Photo %}
       <img src="/Lab Members/{{ current.Photo }}" alt="Current Lab Member"></img>
       <div class="member-content icon-offset">
       {% else %}
       <div class="member-content">
       {% endif %}
       {% if current.Name %}
       <h4>{{ current.Name }}</h4>
       {% endif %}
       {% if current.Position %}
       <p>{{ current.Position }}</p>
       {% endif %}
       </div>

In this case current.Photo has the name file for the picture I want it to load. The picture loads perfectly but it is not getting cached. This is not a issue when I am running my website locally but then I get errors 500 (only of a few of the pictures, and which pictures get the error varies whenever you reload) when I am running it off my hosting company. The error I was getting is that the page was using too much of the memory and couldn't display the website. I believe that if grav cached the images I would not have problems with the memory.

Also, I have tried using twig to call out the image:

TWIG
       <img src="{{ page.media[current.Photo].url }}" alt="Current Lab Member"></img>

The image shows but when I check on chrome the link is not that of the cached image but of the actual picture.

Thank you for taking the time to read this, and thanks for the help.
-Juan Luis

10 years ago

@Juan Luis, try this:

TWIG
{{ page.media['current.Photo.jpg?cache'].url }}

This solution is from Andy in this chat post

10 years ago

Correct, by default if you perform no media operations, the image is accessed directly as there's no point doing work on an image that is unchanged. However, using the ?cache option forces the image to be cached even though technically no operations have been performed.

10 years ago

How do I cache the pictures, when my code looks like this:

{{ page.media[row.image].html() }} ?

THX in advance!

10 years ago
TWIG
{{ page.media[row.image].cache.html() }}
10 years ago

Do you know why this isn't working:

TWIG
<div style="background-image:url({{ page.media.images[item.background ~ '?cache'].url }});">

I only get

TXT
<div style="background-image:url();">

It works with this but image is not cached

TWIG
<div style="background-image:url({{ page.media.images[item.background].url }});">

Thanks!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1350 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4061 9 years ago
Archive · by Muut Archive, 9 years ago
1 2948 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago