phwa4563 phwa4563 - 3 years ago 484
HTML Question

Render HTML Tag attribute using mustache

In my mustache template I do have something like:

<div {{attr}}="{{attrVal}}"></div>

Rendering this using

Mustache.render(template, {attr : 'data-test', attrVal : 'test'})

does produce

<div ="test"></div>

I expect to get something like

<div data-test="test"></div>

Isn't it possible to render attribute name inside of a tag using Mustache?


I figured out the problem. I define my HTML Mustache Templates inside custom
tags in my document. For example:

<template id='myTemplate'>
<div {{dataAttr}}="{{dataAttrValue}}"></div>

When getting the template using
the browser does convert the
because attributes are case insensitiv. So calling

{ dataAttr : 'data-attr', dataAttrValue : 'test'}

Results in

<div ="test"></div>

Answer Source

What you're doing there actually looks correct. As an example, check out:,js,console

Is it possible template isn't defined properly?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download