CMS Style rendering Templates in EPiServer Commerce 7.5
1.
Create a Content Type
We can use CMS-style rendering template in EPiServer
Commerce 7.5. to use rendering template for a Node or an Entry, we need to
define a content type class e.g.
using EPiServer.Commerce.Catalog.ContentTypes;
using EPiServer.Commerce.Catalog.DataAnnotations;
using EPiServer.DataAnnotations;
namespace EPiServer.Commerce.XYZ
{
[ContentType]
public class FashionItemContent : VariationContent
{
[Encrypted]
[CultureSpecific]
public virtual string Description { get; set; }
[SaveHistory]
public virtual int Size { get; set; }
}
}
2.
Define templates
It is possible to have several templates defined for the
same model. If you want to display a Node/Entry on your site, you can do so by
creating a template in the same way as we do with CMS content. e.g.
[TemplateDescriptor(Default
= true)]
public partial class DefaultFashionItemTemplate : BlockControlBase<FashionItemContent>
{
}
[TemplateDescriptor(Tags
= new string[] { EPiServer.Framework.Web.RenderingTags.Sidebar
})]
public partial class SidebarFashionItemTemplate : BlockControlBase<FashionItemContent>
{ }
In MVC to render a ContentArea property you can specify the
tag by using Tag attribute as follows
<% Html.PropertyFor(m => m.MyContentArea, new { Tag = EPiServer.Framework.Web.RenderingTags.Sidebar })%>
<% Html.PropertyFor(m => m.MyContentArea, new { Tag = EPiServer.Framework.Web.RenderingTags.Sidebar })%>
3. Registering new routing
To use new renderer template, you need to register new
routing mode.
using System.Web.Routing;
using EPiServer.Commerce.Routing;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
namespace EPiServer.Commerce.XYZ
{
public class RegisterRoutingModuleSample : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
MapRoutes(RouteTable.Routes);
}
private static void MapRoutes(RouteCollection routes)
{
CatalogRouteHelper.MapDefaultHierarchialRouter(routes, true);
}
public void Uninitialize(InitializationEngine context) { /*uninitialize*/}
public void Preload(string[] parameters) { }
}
}
Great news about cms stylr rendering templates.
ReplyDeleteCMS Development Company