July 27, 2012

WFFM - Use a display name for the email in the send action

To "Send Email Message" save action of webform for marketers you may change the field "Parameters" in the item: /sitecore/system/Modules/Web Forms for Marketers/Settings/Actions/Save Actions/Send Email Message.

The default value is:
<Host>example.host</Host><From>example@mail.net</From><IsBodyHtml>true</IsBodyHtml>
Now, if you need to have a different display name for the "from" than just dispaly the email itself you can just add the display name in double quotes before the email like this:
<Host>example.host</Host><From>"My Display Name" example@mail.net</From><IsBodyHtml>true</IsBodyHtml>

July 16, 2012

Create a custom remote event in sitecore - Demo

I have multiple comments on the post about the custom remote events, so I will give you a more complete example. If you need more information about how those events work please refer to the previous post.

You can download the full exaple as a zip file here.

In this example, I have also added a parameter in the event.

  • The event:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.Serialization;
    
    namespace BOL.Events
    {
        [DataContract]
        public class ClearCacheEvent
        {
            public ClearCacheEvent(string cacheName)
            {
                this.CacheName = cacheName;
            }
    
            // Properties
            [DataMember]
            public string CacheName { get; protected set; }
    
        }
    }
  • The event argument with the parameter:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Sitecore.Events;
    
    namespace BOL.Events
    {
        [Serializable]
        public class ClearCacheEventArgs : EventArgs, IPassNativeEventArgs
        {
            public string CacheName { get; set; }
    
            public ClearCacheEventArgs(string cacheName)
            {
                this.CacheName = cacheName;
            }
        }
    }
    
  • The event handler:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Sitecore.Diagnostics;
    using Sitecore.Events;
    
    namespace BOL.Events
    {
        public class ClearCacheEventHandler
        {
            /// 
            /// This methos is used to raise the local event
            /// 
            /// 
            public static void Run(ClearCacheEvent @event)
            {
                Log.Info("ClearCacheEventHandler - Run", typeof(ClearCacheEventHandler));
                ClearCacheEventArgs args = new ClearCacheEventArgs(@event.CacheName);
                Event.RaiseEvent("clearcache:remote", new object[] { args });
            }
        }
    }
  • The hook to register the event:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Sitecore.Events.Hooks;
    
    namespace BOL.Events
    {
        public class ClearCacheHook : IHook
        {
            public void Initialize()
            {
                Sitecore.Eventing.EventManager.Subscribe(new Action { ClearCacheEventHandler.Run });
            }
        }
    }
    
  • The code to trigger the event:
    public class TriggerEvent
    {
     public void Trigger()
     {
      ClearCacheEvent inst = new ClearCacheEvent("Navigation");
      Sitecore.Eventing.EventManager.QueueEvent(inst);
     }
    }
  • The config file to register the event:
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
      <sitecore>
     <hooks>  
      <hook type="BOL.Events.ClearCacheHook, BOL"/>  
     </hooks> 
     
     <events>
      <event name="clearcache:remote">
       <handler type="Shurgard.Events.ClearStoreCache, Shurgard.Events" method="OnRemoteClearStoreCache"/>          
      </event>
     <events>
     
      </sitecore>
    </configuration>

July 9, 2012

Image Extension Module

I have release a new module on trac. This module is an extension of the sitecore control <sc:Image /> who add 2 possibilities:
  • Use the real file extension in place of the .ashx used by sitecore. (This functionality is better for the SEO but also allow you to apply a transparency filter on IE6 to your PNG files.)
  • Set a default image who will appear when the image field is empty. This setting is configurable at two level: on the site level and control per control.
For the documentation of this module click here.