Search code examples
javascriptrubymustachejekyllliquid-layout

How to use mustache.js inside of a site generated with Jekyll and Liquid Layouts all together


I have a site built in Jekyll for rapid prototyping of a JavaScript project I'm working on: Choropleth

Now I've decided to introduce mustache.js into the project and obviously I ran into the issue of the liquid layouts {{}} syntax conflicting with mustache's syntax.

Does anyone know of a way that I can simply use the Set Delimiter feature of mustache to change how mustache is working in my project? How can I put the write syntax into my JS generated by Jekyll/Liquid?


Solution

  • In my page that I put in the _posts folder (default jekyll setup) I have the following:

    ---
    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}=}}"
    ---
    

    Then down below I have the following test line:

    // 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));
    

    It works like a charm.