javascript - need advice on dust temmplate -


i new dust (linkedin), working on first little template. after writing obvious (but long) way thought of way optimize using inline partial. long version looks this:

{#parcours}<tr class="pcsel_pc" id="{id}"> <td class="pcsel_exp_btn"><a href="#"  class="list{?exp}hide{:else}exp{/exp}btn"> <span class="glyphicon glyphicon-{?exp}minus{:else}plus{/exp}"></span></a></td> <td class="pcsel_col">{name}</td><td class="pcsel_col pcsel_num">{count}</td> </tr> {?exp} {#variants} <tr class="pcsel_var{?sel} pcsel_sel{/sel}" id="{id}" > <td class="pcsel_col">&nbsp;</td><td class="pcsel_var pcsel_col">{name}</td> <td class="pcsel_col pcsel_num">{count}</td> </tr> {/variants} {:else} {#variants} <tr class="pcsel_var pcsel_hide" id="{id}" > <td class="pcsel_col">&nbsp;</td><td class="pcsel_var pcsel_col">{name}</td> <td class="pcsel_col pcsel_num">{count}</td> </tr> {/variants} {/exp} {/parcours} 

explanation: have context parcours contains inner context variants. if variable exp not exist in outer context, want use class pcsel_hide in inner context. solution works code inner context contained twice kind of stupid. thought of way use inline partial conditionally set in outer context , used in inner context:

{#parcours}<tr class="pcsel_pc" id="{id}"> <td class="pcsel_exp_btn"><a href="#"  class="list{?exp}hide{:else}exp{/exp}btn"> <span class="glyphicon glyphicon-{?exp}minus{:else}plus{/exp}"></span></a></td> <td class="pcsel_col">{name}</td><td class="pcsel_col pcsel_num">{count}</td> </tr> {?exp}{<hide/}{:else}{<hide} pcsel_hide{/hide}{/exp} {#variants} <tr class="pcsel_var{+hide/}{?sel} pcsel_sel{/sel}" id="{id}" > <td class="pcsel_col">&nbsp;</td><td class="pcsel_var pcsel_col">{name}</td> <td class="pcsel_col pcsel_num">{count}</td> </tr> {/variants} {/parcours}  

this version nice , short, doesn't seem job. see class pcsel_hide time if outer context contains exp , uses correct classes. ideas ?

this because inline partials statically evaluated before template rendering begins. last version of inline partial defined same name wins.

inline partials cannot conditionally evaluated this. want instead use logic helper {@eq}.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -