【问题标题】:How to use mustache.js inside of a site generated with Jekyll and Liquid Layouts all together如何在使用 Jekyll 和 Liquid 布局生成的网站中同时使用 mustache.js
【发布时间】:2013-02-03 02:00:43
【问题描述】:

我有一个用 Jekyll 构建的网站,用于对我正在处理的 JavaScript 项目进行快速原型设计:Choropleth

现在我决定在项目中引入mustache.js,显然我遇到了流动布局 {{}} 语法与 mustache 语法冲突的问题。

有没有人知道我可以简单地使用 mustache 的 Set Delimiter 功能来更改 mustache 在我的项目中的工作方式?如何将写入语法放入 Jekyll/Liquid 生成的 JS 中?

【问题讨论】:

    标签: javascript ruby mustache jekyll liquid-layout


    【解决方案1】:

    过去(一年多前)我发现它有问题,但我记得必须在我的实际模板中包含分隔符设置。例如:

    {{=[[ ]]=}}
    
    <div>There have been <strong>[[numVisits]]</strong> visits to this site!</div>
    
    [[={{ }}=]]
    

    虽然我不确定最初的 {{ 是否会被正确解释,因为其他一些库正在查看相同的模板。

    【讨论】:

      【解决方案2】:

      在我放入 _posts 文件夹的页面中(默认 jekyll 设置),我有以下内容:

      ---
      layout:      test
      categories:  tests
      comments:    false
      date:        2013-02-02 21:15:30
      title:       Version 0.1.1 - geoJSON From Google Docs
      subtitle:    Grab the Data from Google Docs Spreadsheet
      
      mustacheSetDelimiter: "{{={u{ }u}=}}"
      ---
      

      然后在下面我有以下测试线:

      // Testing mustache template: use this to set new delimiter tags {{page.mustacheSetDelimiter}}
      console.log(Mustache.render("{{page.mustacheSetDelimiter}} County name: {u{countyname}u}", masterGeoJSON.features[0].properties));
      

      它就像一个魅力。

      【讨论】:

      • 后站:20/20 我应该将变量命名为“setMustacheDelimiter”
      • 对于今天之后看到此内容的所有人,我只想让你们知道,我花了 5 个多小时来寻找 Mustache 没有呈现我的视图(数据)的原因。 @Jeremy,我非常感谢你的拯救!!!
      猜你喜欢
      • 1970-01-01
      • 2013-07-24
      • 2015-03-06
      • 2020-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多