Boolean tokens in Orchard CMS

Say I have a Contact Form in the Orchard CMS that I created that had the following fields

  Name:
 Email Address:
 Message:
 Newsletter:

Now, having sent this form, I set it to send a specific email address by email, and I use tokens for the four fields to create an email so that the resulting email can look like this.

Name: John Smith

Email Address: jsmith@example.com

Message: Hello! I love your site and I hope you get more content that I can use in the future!

Newsletter: True

Now that’s fine, but the last Newsletter field is logical, and I would like the text presented here to be Yes / No (or perhaps other custom words). How to replace the default True / False defaults for email for custom?

+4
source share
1 answer

To do this, you probably need to implement your own token provider. Here is an example from the Orchard.Fields module ... FieldTokens.cs

Please note that there is no direct link to the Orchard.Tokens project, so they use the event bus convention, where you can define your own interface with the same name and signature as the other event handler. Orchard will see this convention and consider your implementation as a handler for these events. I only mention this because at first it confused me. You can directly reference the token module if you wish.

+2
source

All Articles