Last updated: Jan 08 2018

Area: Episerver Add-ons Applies to versions: 2 and higher

Searching block templates

Note: Episerver Forms is only supported by MVC-based websites and HTML5-compliant browsers.

This topic describes the ICustomViewLocation interface in Episerver Forms. This interface provides paths for searching element block views.

How it works

These interface implementations return an array of paths. These paths are used by Forms.Core to look up view template for Blocks.

Examples

CustomViewLocationBase is a base implementation (in Forms.UI) for this interface, and FormsViewLocation is the default implementation in Forms.

  /// <summary>
   /// Default element block view location paths.
   /// </summary>
   [ServiceConfiguration(typeof(ICustomViewLocation))]
   public class FormsViewLocation : CustomViewLocationBase
   {
       public override int Order { get { return 1000; } set {} }
       public override string[] Paths
       {
           get
           {
               return new string[] { EPiServerFormsSection.Instance.FormElementViewsFolder, GetDefaultViewLocation() };
           }
       }
   }

Suppose the Forms.Samples project has this class. Forms.Core looks for Element template in ~/Views/Samples/ElementBlocks and the default view location of the Samples add-on (in ~\modules\_protected\EPiServer.Forms.Samples\Views\ElementBlocks).

   [ServiceConfiguration(typeof(ICustomViewLocation))]
   public class FormsSamplesViewLocation : CustomViewLocationBase
   {
       /// <summary>
       /// This will be loaded before path of Form.Core
       /// </summary>
       public override int Order { get { return 500; } set { } }
       public override string[] Paths
       {
           get
           {
               return new string[] { "~/Views/Samples/ElementBlocks", GetDefaultViewLocation() };
           }
       }
   }

Comments

I'm using Episerver.Forms v4.8.0 and the above code sample seems to be incorrect (perhaps changed in recent Forms version?), the FormsViewLocationBase should now be CustomViewLocationBase. So like this:

public class FormsSamplesViewLocation : CustomViewLocationBase

Matt

You are right. Thank you.

The inheritance tree is


in Forms.UI package, we have the base class

CustomViewLocationBase : ICustomViewLocation


in Forms package, we have this class, which provides templates for built-in FormsElements

FormsViewLocation : CustomViewLocationBase


It always should be CustomViewLocationBase from the beginning. The sample code might be written using old-obsoleted-class-naming.