(Handlebar.JS)Best way to output different templates for items with certain keys

107 Views Asked by At

I am stuck already with this problem for more than a day, the idea is that would like somehow to also add a comma between each of the items and a full stop at the end.

        {{#each items}}
         <button class="accordion-button"
           {{#if (equals type "article")}}  {{AUTHOR}} {{TITLE}} {{JOURNAL}} {{VOLUME}}({{NUMBER}})                       {{/if}}
           {{#if (equals type "book")}} {{AUTHOR}} {{EDITOR}} {{BOOKTITLE}} {{/if}}
         </button>    
        {{/each}}

I was suggested to add a custom helper for each handlebar and it worked partially as I am not able to find the last element and add a full stop to it. Is there any way to get all the existing handlebars between the {if}........{/if} statement and loop through them?

One .json entry:

    {
    "key": "ACM94b",
    "type": "article",
    "AUTHOR": "Adam",
    "INSTITUTION": "ACM",
    "JOURNAL": "Communications of the ACM",
    "KEYWORDS": "scglib",
    "MONTH": "May",
    "NUMBER": "5",
    "TITLE": "Reverse Engineering",
    "VOLUME": "37",
    "YEAR": "1994"
},

Thank you for your time.

0

There are 0 best solutions below