Hellama - Generator function

Back to Hellama

The replacement can be also a generator function which takes three params. The signature is F(E,A,key), where E is the element where the generator function was called, A is the attribute and key the replacement value (inc in the code below). Changing the surrounding DOM (the nodes that are processed) could be defined, but intentionally is not as it leads to tangled behavior. Always keep it straight and simple.

<ul id="test" data-foreach="items"> <li>{inc}</li> </ul> const cfg = { open: "{", close: "}" }; var i = 0; const counter = (E,A,key) => E.innerHTML = ++i; const tags = { items: new Array(10).fill({inc:counter}) }; hellama([test], tags, cfg);