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

Get screen/browser width with twig

first-time

Started by Florian 9 years ago · 2 replies · 9164 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 Paul Hodges, 4 weeks ago
19 484 5 days ago
Support · by Lauw, 7 days ago
2 99 7 days ago
Support · by Anna, 3 weeks ago
4 426 1 week ago
Support · by gtx, 4 weeks ago
4 377 3 weeks ago
Support · by Anna, 1 month ago
9 484 3 weeks ago