Skip to main content

I’d like to be able to supply a template to skuid.uitls.mergeAsText() that is either in the form of row merge {{Name}} or global merge {{$Model.MyModel.data.0.Name}}.

Can mergeAsText() handle that? and how?

Or do I need to create an if or switch/case statement to determine the mode before I run the function?

This method is not documented in the API yet, but we use it so frequently and it’s so useful… it’s a travesty that it’s not documented yet. Therefore I present it to you:

skuid.utils.mergeAsTextInContext(template,context)

Basically it’s the same as mergeAsText() except much much simpler to use, just pass it a template and any context you may or may not have. This method does exactly what you’re after, automatically deciding on what mode to use depending on whether or not the context parameter is present and contains a row or modelkey — if neither are present, it will run in global merge mode, if just model is present, it will run in model merge mode, and if both model and row are present, then it will run in row merge context, e.g.

// Will run in row merge mode
var result = skuid.utils.mergeAsTextInContext(‘{{FirstName}} {{LastName}}’,{ model: myModel, row: myModel.getFirstRow() });

// Will run in model merge mode
var result = skuid.utils.mergeAsTextInContext(‘{{Model.labelPlural}}’,{ model: myModel });

// Will run in global merge mode
var result = skuid.utils.mergeAsTextInContext(‘{{$User.firstName}}’);



awesome!