jsonhandlebars.jstemplatingassembleatomic-design

assemble.io partial pass data to nested partials


I am using assemble.io and I would want to modularize everyhing using the "atomic design" principles.

Let's say that I start with a couple of single atoms

atomic partial "title" (a-h2-title.html)

<h2 class="{{additionalclasses}}">{{title}}</h2>

atomic partial "info text" (a-info-text.html)

<div class="info {{additionalclasses}}">
   {{{text}}}
</div>

As far as I have understood, if I want to use "instances" of these generic components with some data I can define them in a json file like in this example:

info-text-example1.html

{{>a-info-text info-text-example1}}

info-text-example1.json

{
   "text":"<p>some text</p>",
   "additionalclasses"="info--modified"
}

Ok, now my problem is when I want to define for example a molecule:

m-text-and-title.html

<div class="box {{additionalclasses}}">
  {{>a-h2-title}}
  {{>a-info-text}}
</div>

Now, if I want an "instance" for this element

text-and-title-example1.html

{{>m-text-and-title ???}}

How can I define all the data for the object itself (additionalclasses) and for the child objects? I hope I have made myself clear

I've already seen this article here but I am not able to adapt it to my case Thank you for your answer


Solution

  • You will still have to create the data structure in a way that you need it, then in the pages or partials pass the values to the sub-partials. So in this case, I think you can use the following pattern:

    text-and-title-example1.html

    {{>m-text-and-title text-and-title-example1}}
    

    text-and-title-example1.json

    {
      "additionalclasses": "text-and-title--modified",
      "title-example": {
        "title": "some title",
        "additionalclasses": "title-modified"
      },
      "text-example": {
        "text": "<p>some text</p>",
        "additionalclasses": "info--modified"
      }
    }
    

    Then update the molecule to be this:

    <div class="box {{additionalclasses}}">
      {{>a-h2-title title-example}}
      {{>a-info-text text-example}}
    </div>
    

    Now this works the same way as your initial example. You have a data object with properties that you've specified, then you pass those properties into the partials that will use them. The "atoms" have generic, reusable properties already and you can change your "molecule" to do the same... like change title-example to title and text-example to text, but keep them as objects that are passed down to the "atoms".