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.

Support

Get screen/browser width with twig

first-time

Started by Florian 9 years ago · 2 replies · 8930 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 Thomas, 1 week ago
2 54 12 hours ago
Support · by Anna, 3 days ago
2 60 15 hours ago
Support · by Justin Young, 15 hours ago
1 30 15 hours ago
Support · by Duc , 1 week ago
2 65 5 days ago
Support · by Colin Hume, 1 week ago
2 57 5 days ago