如何成功地将Middleman frontmatter变量集成到用haml编写的布局页面的javascript片段中?
昨天我决定找中间人和哈姆,他们太棒了! 因为我不想只为一个值创建多个布局,所以我尝试使用frontmatter变量来更改布局页面底部javascript片段中的值 javascript片段被包装在如何成功地将Middleman frontmatter变量集成到用haml编写的布局页面的javascript片段中?,javascript,haml,preprocessor,middleman,yaml-front-matter,Javascript,Haml,Preprocessor,Middleman,Yaml Front Matter,昨天我决定找中间人和哈姆,他们太棒了! 因为我不想只为一个值创建多个布局,所以我尝试使用frontmatter变量来更改布局页面底部javascript片段中的值 javascript片段被包装在:javascript过滤器()中,该过滤器触发jQuery插件。插件需要一些变量。我想在其他页面中更改的变量是top。根据middlemanfrontmatter指南页面(),您只需在布局页面中希望该变量的位置添加。这个字符串用erb编写,在=current_page.data.top中被翻译成ham
:javascript
过滤器()中,该过滤器触发jQuery插件。插件需要一些变量。我想在其他页面中更改的变量是top
。根据middlemanfrontmatter指南页面(),您只需在布局页面中希望该变量的位置添加
。这个字符串用erb编写,在=current_page.data.top
中被翻译成haml,但是当我在浏览器中运行页面时,开发人员控制台告诉SyntaxError:expected expression,get'='
如何成功地将Middleman frontmatter变量集成到用haml编写的布局页面的javascript片段中
布局页面的底部(代码段所在的位置)如下所示:
/ content of the layout the page
:javascript
$('#sidenav').simplerSidebar({
opener: '#toggle-sidenav',
top: = current_page.data.top
animation: {
easing: 'easeOutQuint'
},
sidebar: {
align: 'right',
width: 320,
closingLinks: 'a',
css: {
zIndex: 3000
}
}
});
我要更改的页面如下所示:
---
top: 30
---
/ rest of the page
我自己设法回答了我的问题。我再次更仔细地阅读了,在这一节中,我读到了“过滤器可以用{}插入Ruby代码。” 基本上,当在过滤器下编码时(无论它是什么过滤器),您应该使用这个
{current_page.data}
,而不是使用Middleman和Haml提供的字符串
在我的例子中,代码段应该是:
:javascript
$('#sidenav').simplerSidebar({
opener: '#toggle-sidenav',
top: #{current_page.data.top},
animation: {
easing: 'easeOutQuint'
},
sidebar: {
align: 'right',
width: 320,
closingLinks: 'a',
css: {
zIndex: 3000
}
}
});
不应该
top:=当前页面.data.top
是top:,
?@JoshCrozier因为布局是用HAML编写的,而不是用ERB编写的,所以字符串被转换为=当前页面.data.top