How do I use Display Tags in Episerver?

  • Page Owner: Not Set
  • Last Reviewed: 2020-02-12

Register the template with the template coordinator.

(From Scratch Site Example)

using Blend.Episerver.Rendering;
using Blend.ScratchSite.Models.Blocks;
using Blend.ScratchSite.Models.Pages;
using EPiServer.Web.Mvc;

namespace Blend.ScratchSite.Business.Rendering
{
    public class TemplateCoordinator : AbstractTemplateCoordinator
    {
        public const string BlockFolderPath = "~/Views/Blocks/";
        public const string PagesFolderPath = "~/Views/Pages/";


        public override string BlockFolder => BlockFolderPath;
        public override string MediaFolder => "~/Views/Media/";
        public override string PagePartialsFolder => "~/Views/PagePartials/";
        public override string PagesFolder => PagesFolderPath;

        protected override void Register()
        {
            RegisterBlock<RichTextBlock>(Constants.DisplayOptions.Featured, Constants.DisplayTags.Sidebar);
            RegisterPartial<BasicPage>();
            RegisterBlock<ExampleBlock>(AptaCoreConstants.TagNames.LatestArticle);
        }
    }
}

Add the Template to your views

Create

Views 
 > Project
    > Blocks
      > ExampleBlock
         > LatestArticle.cshtml

Pass the tag into the renderer

Use either

(APTA Example)

@Html.PropertyFor(x => item, new { Tag = AptaCoreConstants.TagNames.LatestArticle })

OR

@{
  Html.RenderContentData(item, false, AptaCoreConstants.TagNames.LatestArticle);
}