Syntax needed - Subexpression generating string to pass to helper
I have a helper "ResourceLookup" used to look up a resource string. But I need to build the name of the resource string from my object tree.
What syntax would I use? In this example I need to get myObj.Type formatted as an argument to the TypeName_ resource string, but I have to have the quotes around TypeName or it doesn't pass it as a string to my helper.
{{ResourceLookup "TypeName_(myObj.Type)"}}
What I get right now is a string that directly contains "TypeName_(myObj.Type)" If I leave off the quotes, I get an error - Message: Token ')' could not be converted to an expression. Appending one more option - if I do {{ResourceLookup TypeName_{{myObj.Type}} }}, I get "undefined" as the value of arg1 in my helper.
Example model:
class Message
{
MessageType Type {get;}
}
(where MessageType is an enum)
...so I need something like
{{ResourceLookup "MessageLabel{{myMsg.Type}}"}}
where I have a different message label localized per message type.
It seems like you are essentially trying to do string concatenation inside the template to build an argument. Handlebars doesn't support that... It doesn't support any kind of operator or "expression" in that sense. It only understands helpers and arguments. The typical approach would be to pass each component as a separate argument and concatenate them inside the helper; or you could use a SubExpression with a concat helper.
Option 1:
{{Lookup "MessageLabel" Type}}
Where Lookup loops over the args and concatenates them.
Option 2:
{{Lookup (Concat "MessageLabel" Type)}}
Where the Lookup helper expects a single argument and the Concat helper will return all the args concatenated as a single string.
Thanks very much, both of those seem very reasonable.