Last active
August 3, 2016 04:37
-
-
Save benmccallum/f3769f2310551379e277cd179edf668f to your computer and use it in GitHub Desktop.
EPiServer - Detecting Block editing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using EPiServer.Core | |
@using EPiServer.Editor | |
@using EPiServer.Web.Mvc.Html | |
@model MyWebsite.Models.BlockTypes.EmergencyNotificationBlock | |
<div class="card-static full"> | |
<div class="emergency-notification"> | |
<div class="icon @Model.AlertType.ToString().ToLower()"></div> | |
<div class="wrapper"> | |
<h2>@Html.PropertyFor(m => m.Title)</h2> | |
<p>@Html.PropertyFor(m => m.Copy)</p> | |
<a href="@Model.LinkPage.Uri" target="_blank" class="cta">More Details</a> | |
</div> | |
</div> | |
</div> | |
@if (ViewBag.IsInBlockPreview == true) | |
{ | |
<div class="page-editing"> | |
<strong>Alert type: </strong> | |
@Html.PropertyFor(m => m.AlertType) | |
<br /> | |
<strong>Link page:</strong> | |
@Html.PropertyFor(m => m.LinkPage) | |
</div> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using EPiServer.Web.Mvc; | |
namespace MyWebsite.Controllers | |
{ | |
/// <summary> | |
/// Preview controller base. | |
/// </summary> | |
public abstract class PreviewController : ActionControllerBase | |
{ | |
public PreviewController() | |
{ | |
// Set a flag for block views to use to detect if the block is being edited vs being rendered in a content area when the whole page is being edited | |
ViewBag.IsInBlockPreview = true; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using EPiServer; | |
using EPiServer.Core; | |
using EPiServer.Framework.DataAnnotations; | |
using EPiServer.Framework.Web; | |
using EPiServer.Web; | |
using EPiServer.Web.Mvc; | |
using MyWebsite.Models.BlockTypes; | |
using MyWebsite.Models.PageTypes; | |
using MyWebsite.Models.ViewModels; | |
using System.Web.Mvc; | |
namespace MyWebsite.Controllers | |
{ | |
[ContentOutputCache(Disable = true, NoStore = true, VaryByParam = "*", Duration = 0)] | |
[TemplateDescriptor( | |
Inherited = true, | |
TemplateTypeCategory = TemplateTypeCategories.MvcController, | |
Tags = new[] { RenderingTags.Preview, RenderingTags.Edit }, | |
AvailableWithoutTag = false)] | |
public class PreviewDashboardCardController : PreviewController, IRenderTemplate<DashboardCardBlockBase> | |
{ | |
public ActionResult Index(IContent currentContent) | |
{ | |
var model = new DashboardPreviewModel(new MyWebsiteBasePage(), currentContent); | |
return View(model); | |
} | |
} | |
} |
Author
benmccallum
commented
Aug 3, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment