Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a way to do more than one level of inheritance value overrides with dust.js?
    primarykey
    data
    text
    <p>I'm using dust templates and one aspect of the design has been bugging me. This makes me wonder if I'm "doing it wrong" so I thought I would ask S.O. Is there a way to create multiple-level inheritance in dust.js with blocks and inline partials? Lets say you have a base template with layout, an inheriting template that overrides some content, and then yet another template inheriting from that template that wishes to selectively override some content. Normally I would imagine it works by the last inheriting template providing the final overriding values. The inline partial syntax, however, seems to only work on a single level. Here's a contrived example that should show what I'm talking about.</p> <p>template 1 <code>test_base.dust</code>:</p> <pre><code>&lt;h1&gt; {+document_title/} &lt;/h1&gt; {+content} &lt;p&gt;Some great content.&lt;/p&gt; {/content} </code></pre> <p>template 2 <code>test_level1.dust</code>:</p> <pre><code>{&gt;test_base/} {&lt;document_title}Level 1{/document_title} {&lt;content} &lt;p&gt;Other great content&lt;/p&gt; {/content} </code></pre> <p>template 3 <code>test_level2.dust</code>:</p> <pre><code>{&gt;test_level1/} {&lt;document_title}Level 2{/document_title} </code></pre> <p>Rendering these templates I get the following results:</p> <pre><code>dust.render('test_base', {}, function(err, data) { console.log(data); } ); "&lt;h1&gt;&lt;/h1&gt;&lt;p&gt;Some great content.&lt;/p&gt;" dust.render('test_level1', {}, function(err, data) { console.log(data); } ); "&lt;h1&gt;Level 1&lt;/h1&gt;&lt;p&gt;Other great content&lt;/p&gt;" dust.render('test_level2', {}, function(err, data) { console.log(data); } ); "&lt;h1&gt;Level 1&lt;/h1&gt;&lt;p&gt;Other great content&lt;/p&gt;" </code></pre> <p>I've read over the docs a few times but it seems like you can inherit templates from multiple levels but you can only override a single template defined block. So am I "doing it wrong"? Is there a way to accomplish multiple level inheritance with selective overrides using blocks and inline partials? Is there another way to do this and keep the templates DRY?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload