Search code examples
javascriptgettextdust.js

Is it possible to create nested helpers in dust.js?


I am evaluating different template engines for i18n purposes and I wonder if it is possible to create nested helpers in dust.js in order to user both i18n and pluralization (or simply variables) for a single sentence.

Consider the following example from PHP/WordPress, which uses gettext along with printf:

<?php printf( _n( 'One Response to %2$s', '%1$s Responses to %2$s', $comment_count ), $comment_count, $post_title ); ?>

Here we have _n() wrapped inside of printf(). Is this possible with dust.js helpers?


Solution

  • Nested helpers are definitely possible within Dust.js, as long as the nested helper is in the body of the outer helper (as opposed to being within the parameters). The @select helper is an example of nested helpers already in wide use.

    {@select key=myKey}
      {@eq value="Yes"}YES{/eq}
      {@eq value="No"}NO{/eq}
      {@default}Neither here nor there{/default}
    {/select}