Else if

Chain several conditions with #} else if(…) {#.

Any number of branches, written the way you would write them in JavaScript. The library does not know the keyword else if — it simply recognises a fragment that continues a block.

<script type="text/template" id="tpl">
    #for(let num of numbers) {#
        #if(num < 0) {#
            <span style="color: red;">#num# (negative)</span>
        #} else if(num === 0) {#
            <span style="color: gray;">#num# (zero)</span>
        #} else {#
            <span style="color: green;">#num# (positive)</span>
        #}#
        <br>
    #}#
</script>
<div id="output"></div>

<script src="https://cdn.jsdelivr.net/gh/richdafunk/hashJS@v1.3.6/hashJS.js"></script>
<script>
    new hashJS("tpl", { numbers: [-5, 0, 3, -2, 7, 0, 1] }, "output");
</script>
Output result:

The compiler classifies each #…# fragment by shape, not by keyword: anything ending in { opens a block, anything starting with } continues or closes one. That is why else if, catch and finally all work without being special-cased.

Two things to watch in this example. The template lives in a <script type="text/template"> block, because #if(num < 0) {# contains a < — inside a <div> the browser would escape it to &lt; and the expression would no longer be valid JavaScript. And the colours are written as names rather than hex codes: # delimits expressions, so a value like #c00 would be read as the start of one.