Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Get screen/browser width with twig

first-time

Started by Florian 9 years ago · 2 replies · 9523 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 TomW, 2 weeks ago
8 227 8 hours ago
Support · by alex, 2 months ago
8 667 23 hours ago
Support · by Supple, 5 days ago
1 98 1 day ago
Support · by TomW, 1 week ago
3 159 3 days ago
Support · by TomW, 6 days ago
2 106 5 days ago