I am writing a processor for the <addFromTemplate> pipeline. I noticed the following code in a number of the examples

  1. var item = args.FallbackProvider.AddFromTemplate(args.ItemName, args.TemplateId, args.Destination, args.NewId);
  2. args.ProcessorItem = args.Result = item;

What do 1 and 2 do?

When you write an <addFromTemplate> pipeline processor, you are actually replacing the default behavior of the ItemProvider.AddFromTemplate method. Every ItemProvider pipeline sends in the native ItemProvider as the args.FallbackProvider. As such, when you call the following, what you are actually doing is analogous to base.AddFromTemplate, wherein you are calling the native logic within your "overriding" (sort of - this isn't really the right term) method:

// analogous to base.AddFromTemplate
var item = args.FallbackProvider.AddFromTemplate(args.ItemName, args.TemplateId, args.Destination, args.NewId);

Since you are writing a processor, the only way to return a result is by setting a property on your Pipeline arguments. As such, we "return" (sort of - again, this isn't really the right term) a result by setting the args.Result property. Additionally, if there are any other processors then they should use the "result" of this processor instead of the item this processor started with as the args.ProcessorItem:

args.ProcessorItem =    // any other processors should use this item
    args.Result = item; // this is the result

More Information:

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.