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.

Themes & Styling

Get first page image in TWIG with "width: 100%" style applied

Solved by Paul Massendari View solution

Started by Usk70 9 years ago · 3 replies · 1819 views
9 years ago

I am trying to get the first page folder image inside a twig template with a "width: 100%" CSS style applied.

I have tried both:

<a href="{{ page.url }}">{{ page.media[0].html('{{ post.title }}', '{{ page.title }}', 'full-width') }}</a>
(with a CSS file with 100% width applied).

and

<a href="{{ page.url }}"><img src="{{ page.media.images[0].url }}" alt="{{ page.title }}" style="width: 100%" /></a>

without success.

Any tips? Thanks.

9 years ago

are you sure it should be page.media.images.url ? try this one, for me it works perfectly:
page.header.image[0]|first.path

👍 1
9 years ago Solution

{{page.media.images|first.url }} will do the trick

👍 1

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 195 2 months ago
Themes & Styling · by Ian, 2 months ago
3 91 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 451 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 45 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 125 3 months ago