可以在Javascript MatchMedia查询中执行Twig 'include‘语句吗?
我试图通过简单地在我们的平板电脑断点处呈现不同的菜单类型来解决另一个问题。
我知道JS不能与服务器通信,但有可能以这种方式执行twig命令吗?
if (matchMedia) {
const mq = window.matchMedia("(min-width: 992px)");
mq.addListener(WidthChange);
WidthChange(mq);
}
// media query change
function WidthChange(mq) {
if (mq.matches) {
// window width is greater than 992px
{% include‘snippet/navbar.rain’with {'type':'Desktop'} %}
} else {
// window width is less than 992px
{% include‘snippet/navbar.rain’with {'type':'Tablet'} %}
}
}
我在网上找不到正确的语法,甚至找不到这是否是一个可能的解决方案的示例。谢谢
https://stackoverflow.com/questions/56449851
复制相似问题