Search code examples
htmlhandlebars.jstemplating

How do you concat a string to a div class name?


For example, <div class="hi_" + "1"> (which doesn't work)

Use case is if I'm templating in handlebars and my code is:

{{#each this}}
     <div class="box_" + {{id}}>
{{/each}}

How would I go about naming my divs?


Solution

  • You can simply insert the placeholder into the class attribute like so:

    {{#each this}}
        <div class="box_{{ id }}"></div>
    {{/each}}