Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Get screen/browser width with twig

first-time

Started by Florian 9 years ago · 2 replies · 9342 views
9 years ago

Hey everyone,

i am new in grav and twig and have a question.
Is there any possibility to get the screen/browser width and write inside a twig variable?

Greetings
Florian

9 years ago

Hello Florian,

You can get some information about the browser from twig using this: https://learn.getgrav.org/themes/theme-vars#browser-object

You can't get the browser width exactly, but it might be able to do what you want. Be aware that your user might resize his browser though, so you might need to do some stuff in css or javascript.

9 years ago

Hi there @flosse !
You can get exact screen width using JavaScript, but in most cases better idea is to use CSS vh and vw units. If you can give us some more about what you're trying to achieve, I'll be happy to try to help!

Suggested topics

Topic Participants Replies Views Activity
Support · by webmasterodp, 7 days ago
4 153 6 days ago
Support · by nwhitfield, 1 week ago
2 133 1 week ago
Support · by stell, 3 weeks ago
5 369 2 weeks ago
Support · by gravinator, 1 month ago
5 558 2 weeks ago
Support · by Gravver, 3 weeks ago
6 346 3 weeks ago