Search code examples
jsonassemble

Data that references other data in assemble.io


I have data being pulled into assemble set-up like this:

 assemble: {
       options: {
         data: '<%= config.app %>/data/*',

To cut down on a lot of repetition, I'd like to include references to some data in other data, like so:

//in personnel.json
var Personnel = {
    "JohnStamos" : {
        "name":"John Stamos"
    }
}

// later on (in locations.json file -- maybe)...
[
    {
        "name": "TentTown",
        "personnel": [
            personnel.JohnStamos,
            personnel.GaryBusey
        ]
    }
]

I'm not sure how to reconcile that with the way assemble loads data, or if it's even reasonably possible. Is there a way to cross-reference data within the data files?


Solution

  • (Note that this information applies to v0.4.x assemble)

    Have you tried just using config templates? The same way you're doing in the gruntfile?

    //in personnel.json
    var personnel = {
      JohnStamos: {
        name: 'John Stamos'
      }
    }
    
    // later on (in locations.json file -- maybe)...
    [{
      name: 'TentTown',
      personnel: [
        '<%= personnel.JohnStamos %>',
        '<%= personnel.GaryBusey %>'
      ]
    }]