You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! After using string-template on a project, I’d like to run an idea for a feature by you and gauge your interest in a pull request.
Our project is an SMS interface for a bus tracking API in our city. Sometimes we use one template in a variety of ways. Take the following string, for instance: “One #9 bus headed to East Lake will arrive at Main and Washington St in 6m. Another headed to Downtown will arrive in 25m.” Notice how the route number (#9), route type (bus — vs. shuttle), and stop name (Main and Washington St) are omitted from the second sentence. This is achieved with a single template:
destination: "{amount}{route}{type} headed to {destination} {verb}{stop} {eta}"
The template is used twice, the first time with values for route, type and stop, the second time without those values. However, we were forced to remove any space before these three variables (as you can see above) to avoid extraneous spaces in the second sentence. This also means that the values for these variables while constructing the first sentence needed to include a space in front. This could be easily addressed by using a regex to remove extra spaces, but it still leaves us with templates that, at a glance, look inconsistent.
Additionally, the value for the stop variable needs to include ' at ' in front. If that word ever needed to change in the future, our client would need to change it in the code, and not the template, which can be confusing to our client. We would much rather they edit these strings in the templates file, which is much friendlier.
I propose the following syntax:
destination: "{amount}{[ ]route}{[ ]type} headed to {destination} {verb}{[ at ]stop} {eta}"
We can use square brackets to attach strings to the front or back of a variable. If the variable is not assigned any value (undefined, empty string, etc.), then the entire thing is omitted (including anything that’s inside the square brackets). This would allow our code to be much cleaner (we wouldn’t need to keep track of which variables require spaces or other words attached to the front or back), and delegate more copywriting decisions to our templates.
Thoughts?
The text was updated successfully, but these errors were encountered:
Hi! After using string-template on a project, I’d like to run an idea for a feature by you and gauge your interest in a pull request.
Our project is an SMS interface for a bus tracking API in our city. Sometimes we use one template in a variety of ways. Take the following string, for instance: “One #9 bus headed to East Lake will arrive at Main and Washington St in 6m. Another headed to Downtown will arrive in 25m.” Notice how the route number (#9), route type (bus — vs. shuttle), and stop name (Main and Washington St) are omitted from the second sentence. This is achieved with a single template:
destination: "{amount}{route}{type} headed to {destination} {verb}{stop} {eta}"
The template is used twice, the first time with values for
route
,type
andstop
, the second time without those values. However, we were forced to remove any space before these three variables (as you can see above) to avoid extraneous spaces in the second sentence. This also means that the values for these variables while constructing the first sentence needed to include a space in front. This could be easily addressed by using a regex to remove extra spaces, but it still leaves us with templates that, at a glance, look inconsistent.Additionally, the value for the
stop
variable needs to include' at '
in front. If that word ever needed to change in the future, our client would need to change it in the code, and not the template, which can be confusing to our client. We would much rather they edit these strings in the templates file, which is much friendlier.I propose the following syntax:
destination: "{amount}{[ ]route}{[ ]type} headed to {destination} {verb}{[ at ]stop} {eta}"
We can use square brackets to attach strings to the front or back of a variable. If the variable is not assigned any value (undefined, empty string, etc.), then the entire thing is omitted (including anything that’s inside the square brackets). This would allow our code to be much cleaner (we wouldn’t need to keep track of which variables require spaces or other words attached to the front or back), and delegate more copywriting decisions to our templates.
Thoughts?
The text was updated successfully, but these errors were encountered: