Skip to content

How to import a JSON file on template? #1177

@didiraja

Description

@didiraja

I'm creating a series of ecommerce emails that uses a huge load of data, as including all this variables on top of files is not an option, I'd like to load this data from a JSON file.

Couldn't find anything on docs of both Maizzle or Front Matter to do that. There's just a few instructions about which expressions is allowed on top of template files.

My workaround is loading JSON files on config.js but whenever I change content from JSON, rendered e-mail does reload but only html content not data from JSON. Forcing me to stop and restart process.

  • config.js
const dataOne = require('./src/path/data-one.json')
const dataTwo = require('./src/path/data-two.json')
const dataThree = require('./src/path/data-three.json')

module.exports = {
  build: {
    // build config object
  },
  locals: {
  // locals variables
  },
  data: {
    dataOne,
    dataTwo,
    dataThree,
  }
}
  • templates/email.html
<p>{{page.data.dataOne.first_name}}</p>

Is it possible to achieve that using Front Matter syntax?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions