Suppose a function greet(template)
that greets a user given a greeting template.
So, template
would be a string like: "Hello, {{name}}"
, and the function greet would have something like:
var message = template.replace("{{name}}", user.name)
In this example, I am using {{name}}
and .replace
as key concepts of the method. But is this the best way to do it?
What is the best syntax for the "string template" and the best way to process it? Keep in mind the only place I will use this template is in this function, so, I don't need a generic way to do it (In other words, things could be hardcoded).
Edit: I am looking for a genric way. I am trying to avoid template literals