Dynamic Template Block? (Rending Templates from Collection)


#1

So I am trying to figure out a way to generate a page completely based on a configuration something simulate to autoform but instead for pages. This will allow for custom dashboards for enterprise customers.

I understand how {{> Template.dynamic template=template data=data}} works by changing out templates dynamically and I can generate a page of single elements using this. However I would like to take it a template further by adding in the power of {{> UI.contentBlock}} I figured that if a element has child elements would could render them using {{> UI.contentBlock}} but the issue that I am having is that all templates including the parents are rendered via {{> Template.dynamic template=template data=data}} Here is a snippit of the code that I have written so far

<template name="autoLayout">
    <div class="export">
      {{#each getConfig}}
        {{#if children}}
          {{#Template.dynamic template=template data=data}}
            {{#each children}}
              {{> Template.dynamic template=template data=data}}
            {{/each}}
          {{/Template.dynamic}}
        {{else}}
            {{> Template.dynamic template=template data=data}}
        {{/if}}
      {{/each}}
    </div>
</template>

using the configuration

 [
    {
      template : "box",
      data : {
        name : "testName",
        value : "testValue"
      },
      children : [
        {
          template : "text",
          data : {
            name : "testName",
            value : "testValue"
          }
        }
      ]
    },
    {
      template : "text",
      data : {
        name : "testName",
        value : "testValue"
      }
    }
  ]

If the template doesnt have any children it will render just find however I cannot seem to render the children inside a {{> UI.contentBlock}} using {{#Template.dynamic template=template data=data}} I was hopping that someone else has an idea of how I can accomplish this. My reason for this is so I can store a pages layout in JSON in a database. This will allow for customizations that do not require extra code to be sent out to every client that may not need them. Once this proof of concept is doesnt then we can get to more advanced things like aggregation templates that run aggregations on certain collections in order to return the result on a page of course this will require children in children but right now I have the first hurdle to cross.

Any ideas?


#2

I figured it out il be releasing a package shortly here is an example object

[
    {
      template : "box",
      data : {
        children : [
          {
            template : "text",
            data : {
              name : "testName",
              value : "testValue"
            }
          },
          {
            template : "box",
            data : {
              children : [
                {
                  template : "text",
                  data : {
                    name : "testName",
                    value : "childChild"
                  }
                },
                {
                  template : "text",
                  data : {
                    name : "testName",
                    value : "childChild"
                  }
                }
              ]
            }
          },
          {
            template : "text",
            data : {
              name : "testName",
              value : "child"
            }
          }
        ]
      }
    },
    {
      template : "text",
      data : {
        name : "testName",
        value : "Main"
      }
    }
  ]