how to replace and re-evaluate template text

  • 1
  • Question
  • Updated 2 years ago
  • Answered
Hi all,
I'm looking for a way to inject template text with merge fields dynamically to my page (at runtime, with JS).

I want to add a text like ".. the latest status is  {{status__c}} .."  and have the merge field transformed to status value.

My idea was to use a template field, set it's new text and render it again.
I replaced the fields text in the HTML DOM element with JS (which works). But after calling the render() method of the template field,  the old/previous content is set again.

Any suggestions?
Photo of andre b

andre b

  • 140 Points 100 badge 2x thumb

Posted 2 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,968 Points 20k badge 2x thumb
If you are trying to update the value to be somthing different than what is in the model - you will have to try something different.  The easiest way to go about this will be to change the value of the field in your model (status__c) and then re-render the template. 
Photo of Mike Dwyer

Mike Dwyer, Champion

  • 4,736 Points 4k badge 2x thumb
If you are using the standard renderer in your javascript, you may have this:

  • skuid.ui.fieldRenderers[field.metadata.displaytype].read( field, value )
The javascript needs to change value before reaching the renderer statement.
Photo of andre b

andre b

  • 140 Points 100 badge 2x thumb
Rob/Mike, thanks for your hints.
I found the merge API is what I was looking for (
var mergedHtml = skuid.utils.merge( 
row ).html();

I think, my problem description was not clear enough.