When you have multiple message templates, it's usually easiest to have one snippet for each template.
However, there are many other ways to do this. In this post, I'll be sharing with you how to handle multiple templates in one snippet, by using keyed lists.
The first step is to create a keyed list with a title and content for each template. A keyed list is a list where each item as a "key" and a corresponding "value".
So in our case, the "key" will be the title, and the "value" will be the content.
{myList=[
"Thank you"="Thank you very much for your order",
"Help?"="Do you need any help with this?",
"Dispatched"="Your order has been dispatched",
"Refund"="Your order has been refunded"]}
I've put each item on a separate line for the sake of clarity, however this isn't necessary.
Looking at the snippet above, you can see how each item in the list has a key and a value.
So:
Key: "Thank you"
Value: "Thank you very much for your order"
...and so on.
In the next step, I'm going to add a {formmenu}
command that will use the keys in the myList list as its options.
{myList=[
"Thank you"="Thank you very much for your order",
"Help?"="Do you need any help with this?",
"Dispatched"="Your order has been dispatched",
"Refund"="Your order has been refunded"]}
Title: {formmenu: name=title; values={=keys(myList)}}
Notice how the {formmenu}
command contains the keys of myList. This is done with this portion of the command:
values={=keys(myList)}
Next, I want the snippet to give me the value corresponding to the key I choose in my {formmenu}
.
Here's how it's done:
{myList=[
"Thank you"="Thank you very much for your order",
"Help?"="Do you need any help with this?",
"Dispatched"="Your order has been dispatched",
"Refund"="Your order has been refunded"]}
Title: {formmenu: name=title; values={=keys(myList)}}
Content: {=myList[title]}
The final line tells Text Blaze to give the value corresponding to the item chosen in the {formmenu}
, which is referenced by the name title
.
This is a pretty advanced way of doing things, but I'm hoping it will help jog your creativity and give you a few ideas of what's possible with list functions.
Got any ideas you want to implement? Reply to the thread and we can work on them together