Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
I iterate all vistor groups used in my Visitor Group Usage gadget. Take a look at:
For some inspiration.
Hi
Thanks for the inspiration. Now i have installed your gadget. I hope my editors will like it. I think it is very helpful.
Thanks to you i now have a code that works. But my code uses currentContentArea.Contents witch is obsolute. Did not find a good solution for that. Do you have a solution?
public override ActionResult Index(SiteBlockData currentContent) { if (PageEditing.PageIsInEditMode) { var currentContentArea = ControllerContext.ParentActionViewContext.ViewData.Model as ContentArea; if (currentContentArea != null) { var visitorGroupRepo = ServiceLocator.Current.GetInstance<IVisitorGroupRepository>(); //Find currentContent in content area. Any better way of doing this? int index = currentContentArea.Contents.IndexOf(currentContent as IContent); var item = currentContentArea.Items[index]; if (item.AllowedRoles != null) { var names = String.Empty; var counter = 0; foreach (var group in item.AllowedRoles) { counter++; var vg = new Guid(group); var loadedVg = visitorGroupRepo.Load(vg); if (loadedVg != null) { if (counter == 1) { names = visitorGroupRepo.Load(vg).Name; } else if (counter < item.AllowedRoles.Count()) { names = names + ", " + visitorGroupRepo.Load(vg).Name; } else { names = names + " and " + visitorGroupRepo.Load(vg).Name; } } } currentContent.VisitorGroups = names; } } } return PartialView(string.Format("~/Views/Shared/Blocks/{0}.cshtml", currentContent.GetOriginalType().Name), currentContent); }
View
@using EPiServer.Editor @model SiteBlockData @if (PageEditing.PageIsInEditMode && !String.IsNullOrEmpty(Model.VisitorGroups)) { <p>Visible to: @Model.VisitorGroups</p> }
Any other feedback?
Hi
I am trying to render a blocks visitor groups. Anybody know how to do this? Since Blocks will be personalised for every contentarea they are used on. I have created a Ignoe field on the block model that i want to render a string showing the personalization informasjon.
[Ignore] public String VisitorGroups { get; set; }
I am thinking that i can get the information i need in the block controller
///
/// Default block controller that pass all blocks to the default repo for block-view with the model
///
public class BaseBlockController : BlockController
{
public override ActionResult Index(SiteBlockData currentContent)
{
//I manage to get the visitor groups on the page. But how do i get the visitor group used on a spesific block on a contentarea
var currentContentArea = ControllerContext.ParentActionViewContext.ViewData.Model as ContentArea;
if (currentContentArea != null)
{
var visitorGroupRepo = ServiceLocator.Current.GetInstance();
var visitorGroupUsage = ServiceLocator.Current.GetInstance();
var contentRepo = ServiceLocator.Current.GetInstance();
}
//I want something like this in the field
currentContent.VisitorGroups = "Visible to: First time visitors, Returning visitors, Uk visitors";
return PartialView(string.Format("~/Views/Shared/Blocks/{0}.cshtml", currentContent.GetOriginalType().Name), currentContent);
}
Anybody?