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.

General

Applying CropResize to background image URL

Started by Pascal 8 years ago · 4 replies · 713 views
8 years ago

Hi guys. I bet this will be pretty easy, but I can't figure it out.
I am displaying an image as a background via in-line css.
Can someone tell me how to apply cropResize to that image before rendering it?

TWIG
        {% for image in entry.images %} 
                <div class="projectimage" style="background: url('/{{ image.path }}');"></div>

Thank you!

last edited 03/30/18 by Pascal
8 years ago

Hm, this does not seem to work after all. That statement doesn't output anything for me …

8 years ago

What is this entry exactly? If this refers to a page, you have to add media to it, exempla

TWIG
{% for entry in page.children %}
{% for image in entry.media.images %
<div class="projectimage" style="background: url('{{ image.cropResize(300,300).url }}');"></div>
{% endfor %}
{% endfor %}
👍 1

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 85 13 hours ago
General · by pamtbaau, 18 hours ago
1 60 17 hours ago
General · by Andy Miller, 1 day ago
0 47 1 day ago
General · by Marcel, 12 months ago
6 350 5 days ago
General · by Duc , 6 days ago
3 44 5 days ago