我正在使用Assemble.io模板系统和Grunt创建网页。有任何方法可以访问我的.hbs试探中的获取变量吗?我需要创建一个简单的条件:
{{#if debug}}
<script src="path_to_script">
{{/if}}并且只在当前?debug=1之后获取param URL的情况下才调用此条件。可以从.hbs模板中获取变量吗?
发布于 2014-07-13 20:39:46
这与静态站点生成器无关,因为查询字符串的值仅在运行时可用。
但是,您可以在.html页面中包含以下代码片段:
<script>
if (window.location.search.substring(1).split('&').indexOf('debug') > -1) {
var s = document.getElementsByTagName('script')[0],
el = document.createElement('script');
el.async = true;
el.src = 'patth_to_script';
s.parentNode.insertBefore(el, s);
}
</script>当您在浏览器http://www.example.com/page?debug中打开它时,所需的脚本将与页面上引用的其他脚本一起加载。
https://stackoverflow.com/questions/24726337
复制相似问题