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

PHP exception "Unsupported operand types" on addCss() call with media queries

Started by Adam Jansch 7 years ago · 1 replies · 562 views
7 years ago

I've just updated a Grav install from 1.5.10 to 1.6.3 (on PHP 7.2.14) and I'm getting a PHP exception "Unsupported operand types".

The stack trace doesn't highlight where in my code the problem lies, but I've managed to track it down to several addCss() calls that include media queries:

TWIG
{% do assets.addCss('theme://css/customizer-min-width-480.css', {'media':'only screen and (min-width: 480px)'}, 106) %}
{% do assets.addCss('theme://css/customizer-min-width-560.css', {'media':'only screen and (min-width: 560px)'}, 105) %}
{% do assets.addCss('theme://css/customizer-min-width-640.css', {'media':'only screen and (min-width: 640px)'}, 104) %}
{% do assets.addCss('theme://css/customizer-min-width-960.css', {'media':'only screen and (min-width: 960px)'}, 103) %}
{% do assets.addCss('theme://css/customizer-min-width-1440.css', {'media':'only screen and (min-width: 1440px)'}, 102) %}

When I delete these my site loads without issue (though obviously without the correct styling).

Am I formatting these addCss() calls properly?

7 years ago

Worked this out. I had to move the priority value into the options array, using the priority key:

TWIG
{% do assets.addCss('theme://css/customizer-min-width-480.css', {'media':'only screen and (min-width: 480px)', 'priority': 106}) %}
{% do assets.addCss('theme://css/customizer-min-width-560.css', {'media':'only screen and (min-width: 560px)', 'priority': 105}) %}
{% do assets.addCss('theme://css/customizer-min-width-640.css', {'media':'only screen and (min-width: 640px)', 'priority': 104}) %}
{% do assets.addCss('theme://css/customizer-min-width-960.css', {'media':'only screen and (min-width: 960px)', 'priority': 103}) %}
{% do assets.addCss('theme://css/customizer-min-width-1440.css', {'media':'only screen and (min-width: 1440px)', 'priority': 102}) %}
👍 1

Suggested topics

Topic Participants Replies Views Activity
Support · by Duc , 8 hours ago
1 34 8 hours ago
Support · by Thomas, 1 week ago
3 105 17 hours ago
Support · by Anna, 4 days ago
2 101 2 days ago
Support · by Justin Young, 2 days ago
1 67 2 days ago
Support · by Duc , 1 week ago
2 106 6 days ago