Search code examples
javascripttemplatesejsrivets.js

Rivets.js attribute depends on several fields


For example I have following piece of code in EJS:

<img src="<%= model.image %>" title="Toggle: <%= model.brandName %> <%= model.productName %>" />

How can I write it in rivets.js template syntax? rv-title may help, but I should put 'Toggle:' text to my model and create a method which will concatenate it with brandName and productName. But I don't want to do as it's not model's responsibility. Any ideas on how should it work in rivets.js?


Solution

  • You could use a oneway binder to achieve this

    http://rivetsjs.com/docs/guide/#binders

    take a look at my answer at How to bind two values using rivets(like some or condittion)? for a similar situation.