This project is read-only.

Is it possible to edit fields on a content part before rendering

Topics: Customizing Orchard
Nov 14, 2011 at 9:06 PM

One of the requirements of the system is to have system emails that would be automatically personalized to the user. I was thinking it would be great to have the body of the email represented as a Body part. So a templated email type would have a Body part, an Emailable part and a Templated part. The emailable part should work great by being able to identify it's parent item and grab the body off of that for use in the email. The templated part would look for keywords in the text of the body and the subject and do string replacements on them for example with the current users first and last name. I thought this could also work well in a generic sense of having templated pages that would recognize the current user and be But for the templated part I want it to be able to recognize certain parts and do substitutions before the part is rendered for display but not when it is rendered for editing. Is it possible to do something like this for the body part and if so where would I hook this in? Maybe on the OnGetDisplayShape of the handler?

Nov 15, 2011 at 12:58 AM
  • You can use an IHtmlFilter to process the BodyPart in whatever way before rendering
  • You should consider the Tokens module for performing those substitutions
  • A while ago I talked about an Email Templating system, and funnily enough I mentioned this earlier in the future Orchard thread (

Obviously this isn't a complete solution, but maybe these are helpful pointers! (I do have some ideas on how to implement Email Templating)

Nov 15, 2011 at 5:18 PM
Edited Nov 15, 2011 at 6:04 PM

Thanks! Is there any documentation or examples on how tokens work?

EDIT: I found bertrand leroy's blog post on the topic. Correct me if I'm wrong but tokens can only be used on parts that have a dependency on ITokenizer therefore none of the default content parts would be able to make use of tokens (for example body).

Nov 15, 2011 at 6:13 PM

That's not exactly how dependencies work.

BodyPart has its own extensibility point - IHtmlFilter. Any IHtmlFilter you create will run any time that BodyPart is displayed. So you can create an IHtmlFilter, import an ITokenizer yourself, and then run the body text through that. Does this make sense?

Nov 15, 2011 at 9:24 PM

Thanks that worked!

Apr 9, 2012 at 5:40 PM
Edited Aug 1, 2012 at 1:55 PM

Thanks, randompete, with Body I have understood (Though, still a problem with TinyMCE+Tokens).

What should I do, if I need to add support for tokens in the Title field? IHtmlFilter is not enough as I can see.

Apr 9, 2012 at 8:25 PM

Take a look at the On* events in handlers. With them you could hook into the events of every content part, also TitlePart.