Search code examples
javascriptjsonnode.jshandlebars.jszurb-foundation

JSON doesn't load using Panini


I'm using Zurb Foundation for Emails and I'm looking to create a really simple multi-language email export system where I have this data/lang.json:

{
  "en": {
        "hello": "hello",
        "welcome": "Welcome to my website"
  },
  "fr": {
          "hello": "Bonjour",
          "other": "Bienvenue sur mon site web"
  }
}

.. and based on the lang attribute of <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

I need to use the corresponding object from the JSON.

Zurb uses Panini and Handlebars so I'm doing this to get started:

{{lang.en.hello}}

.. but nothing shows up on the page. What am I doing wrong?


Solution

  • Most likely there the src/data directory is missing in the gulpfile.babel.js around line 50.

    .pipe(panini({
          root: 'src/pages',
          layouts: 'src/layouts',
          partials: 'src/partials',
          helpers: 'src/helpers',
          data: 'src/data'
    

    If you want the browser reload function to work you should also add a watch expression with the others (around ln:106):

    gulp.watch('src/data/**/*.json').on('change', gulp.series(resetPages, pages, inline, browser.reload));
    

    See also https://github.com/zurb/panini

    Good luck!