
The first thing you need to do is create a variable that will hold the data you want to pass into your pipeline processor. This variable can be udpated by your deployment process to hold the value you want in each environment.
<sc.variable name="mySites" value="mySitesValue" />
Important: You of course want to create this variable in a patch file and not directly in any of the default Sitecore configuration files.
Next, you want to setup your pipeline configuration. This, of course, is also done by using a patch file.
1 2 3 4 5 | <processor sites="$(mySites)" patch:after="processor[@type='where ever you are patching']" type="MyAssembly, MyNamespace.MyMethod"> <allowedSites>$(sites)</allowedSites> </processor> |
The main thing to understand here is the indirection that is happening with this variables. The first variable config you created as the name of "mySites", this links to the "sites" property in the processor config. The "sites" property then push that value to the "allowedSites" configfuration variable. The "allowsSites" is the property that needs to be exposed on your class file as a public property.
public string AllowedSites { get; set; }
Now when you deploy your code the "AllowedSites" property will have the value that was set in your first "sc.variable" config file. This allows you to use a deployment process to change the value of that variable based on your environment. Now you can control your pipeline code based on this information.
if (!this.AllowedForSite()) { // do some work here } private bool AllowedForSite() { return !this.AllowedSites.Any() || this.AllowedSites.Contains(Context.Site.Name); }
This little feature adds a lot of flexability to your pipeline code. This is the type of feature I like, simple but powerful.
Comments