title: Templating solution for nested variables using nunjucks or other method
body: <p>I have just started using gulp &amp; nunjucks for templating (emails in this case). </p>
  
  <p>I want to solve the problem of calling a module/partial and assigning different values to the attributes each time that it is processed. </p>
  
  <p>It initially seems like a job for a for loop but the module will not necessarily be called upon in sequence within the template</p>
  
  <p>Within the module there are attributes which are assigned to variables. 
  I would like to resolve those variables differently depending on the section that the module is being used for. </p>
  
  <p>A very basic example would be - in an index file I'd have : </p>
  
  <pre><code>{% block content %}
  
  
  &lt;!-- logo start --&gt;
  
  {% include genericMod %}
  
  &lt;!-- logo end --&gt;
  
  
  &lt;!-- some other section start --&gt;
  
  {% include someOtherMod %}
  
  &lt;!-- some other section end --&gt;
  
  
  &lt;!-- hero start --&gt;
  
  {% include genericMod %}
  
  &lt;!-- hero end --&gt;
  
  
  {% endblock %}
  </code></pre>
  
  <p>And in the genericMod itself-:</p>
  
  <pre><code>&lt;tr&gt;
  
   &lt;td class="full-width-image" align="{{align}}" &gt;&lt;img src="{{src}}" alt="{{alt}}"/&gt;&lt;/td&gt;
  
  &lt;/tr&gt;
  </code></pre>
  
  <p>The kind of functionality I'd like to tap into would be to define a “modKey” i.e. a variable within each variable in the module
  e.g. </p>
  
  <pre><code>{{modKey.align}}
  
  {{modKey.src}}
  
  {{modKey.alt}}
  </code></pre>
  
  <p>Then be able to somehow assign that key to the module each time it is called: </p>
  
  <pre><code>&lt;!-- logo start —&gt;
  
  {% include genericMod "modKey": "logo" %}
  
  &lt;!-- logo end --&gt;
  </code></pre>
  
  <p>So the above produces: </p>
  
  <pre><code>&lt;tr&gt;
  
   &lt;td class="full-width-image" align="{{logo.align}}" &gt;&lt;img src="{{logo.src}}" alt="{{logo.alt}}"/&gt;&lt;/td&gt;
  
  &lt;/tr&gt;
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>&lt;!-- hero start --&gt;
  
  {% include genericMod "modKey": "hero" %}
  
  &lt;!-- hero end --&gt;
  </code></pre>
  
  <p>produces: </p>
  
  <pre><code>&lt;tr&gt;
  
   &lt;td class="full-width-image" align="{{hero.align}}" &gt;&lt;img src="{{hero.src}}" alt="{{hero.alt}}"/&gt;&lt;/td&gt;
  
  &lt;/tr&gt;
  </code></pre>
  
  <p>So that when piped through a json file the respective data would be rendered for each attribute variable: </p>
  
  <pre><code>"logo": {
      "alt": "some logo alt text",
      "href": "http://www.someurl.com",
      "align": "left"
    },
   "hero": {
      "alt": "some hero alt text",
      "href": "http://www.someotherurl.com",
      "align": "centre"
    }
  </code></pre>
  
  <p>Obviously that's just a hypothetical solution but is there a way of actually achieving something similar? </p>