Personalization views in edit mode

A
A
Vote:
 

I have 3 personalization/visitor groups, all check for the existance and value of a cookie.

When in 'on-page-eiditing' mode I toggle the groups through the personalization toggle (eye icon > people icon) to switch between the cookie values.

My challenge is to apply a class to the html or body tag(s) when this is toggled in 'on-page-editing' mode.

I saw there is a property on the VisitorGroupCriterion called 'ScriptUrl' and it sounds like it will load this script based on what audience was selected in the toggle. My understanding is that this script will get loaded when this toggle is selected but the page is not loading this script on 'on-page-edit' mode or in the public view.

How can i apply a new class to the html/body tag through the audience toggle in 'on-page-edit' mode?

#199190
Edited, Nov 19, 2018 23:55
Vote:
 

If you're just looking to apply the class when the visitor group is being impersonated in edit/preview mode then you could do something like the following as the ID of the impersonated visitor group is passed in the querystring:

var impersonatedVisitorGroupId = Request.QueryString["visitorgroupsByID"];
Guid visitorGroupGuid;
var className = string.Empty;
if (!string.IsNullOrEmpty(impersonatedVisitorGroupId) && Guid.TryParse(impersonatedVisitorGroupId,out visitorGroupGuid))
{
    var visitorGroupRepo = ServiceLocator.Current.GetInstance<IVisitorGroupRepository>();
    var vgName = visitorGroupRepo.Load(visitorGroupGuid).Name;
    className = "vg-" + Regex.Replace(vgName, "[^a-zA-Z0-9-_]", "-").ToLower();
}

The code above gets the visitor group ID from the query string, gets the name of the group from the IVisitorGroupRepository and converts it into a class name which you could then pass back into your viewmodel to render into the class attribute of the body tag on the page.

#199208
Nov 20, 2018 11:50
A
Vote:
 

@Paul - thanks for the reply

I like the approach but am confused about where that code would go.
Are you implying I should write an 'edit mode' controller that can evalutate this logic?

Initially I thought I could do this in my CookieCriteria class inside of the IsMatch method but the CookieCriteria class does not get called when I toggle through the eye toggle

#199219
Nov 20, 2018 17:08
Vote:
 

I'm assuming you're looking to add the class to the body tag in the layout file used by your pages. I'm also assuming you're using a view model to pass non-page-specific data to your view. If both of those are true then you could add the className as a property to the view model and that logic could go into the same place as the logic to populate your view model. In the case of an alloy site that would be the PageViewContextFactory. If it's just relevant to one page type then it could go into the controller for that page type.

#199223
Nov 20, 2018 19:31
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.