The DisplayChannel will be evaluated for all pages. However if you only want to apply it to certain templates (where the template states which model/page types it handles) then you only add matching tags for those templates.
The template selection will prefer templates that have a tag that matches the DisplayChannel but if no such template exist it will fallback and use another template(most suitable template according to context). In edit mode the editor will be able to select to view the page with your DisplayChannel but if there is no matching template the result will be the same as he/she did not select the channel.
Maybe I misunderstood your answer, but my issue is with the UI, not the functionality.
I only want my custom channels to show up in the UI, if the current page is of type XYZ.
Currently, they are always listed as options, and as you stated, if there is no template, nothing changes, but I want it to only be visible for this one particular page type.
The answer is no. The settings in the "eye" are sticky for the UI and always show the same values, regardless of content. If you compare with visitor groups, the EPiServer 6 UI only shows the visitor group for the current page while EPiServer 7 shows all visitor groups in the system. The idea is that the editor should be able to defined the settings (visitor groups, channel and resulution) and then change content without having to redefine these settings.
That makes sense, thanks for the clarification. What I am in effect after is a way to toggle the various states of a a page while in edit mode. A basic example would be a page with a form with validation messages that are hidden by default, a "page-state" switch would then let me change the page state between "normal" and "error" (where "error" shows all valiadtion errors). Obviously the view/controller has to be coded to support this, but it would be hugely beneficial to be able to expose various states of a page from the editor.
Any ideas how anything like that could be implemented using EpiServer 7?
I wrote some code that checks if a certain channel is active or not. In this case I placed the code in the start page template but you can add it wherever you like:
public partial class StartPageTemplate : SiteTemplatePage<StartPage>
private readonly DisplayChannelService _displayChannelService;
: this(ServiceLocator.Current.GetInstance <DisplayChannelService>())
public StartPageTemplate(DisplayChannelService displayChannelService)
_displayChannelService = displayChannelService;
public bool IsMobileActive
return _displayChannelService.GetActiveChannels(new HttpContextWrapper(HttpContext.Current))
.SingleOrDefault(c => c.GetType() == typeof(MobileChannel)) != null;
And to see that it works I added the following to the code front:
<%=IsMobileActive ? "mobile" : "default"%>
If I register a customer display mode like this:
DisplayChannelService channelSvc = context.Locate.DisplayChannelService();
ContextCondition = ctx => false // replace with real condition
Is there any way of making it so it only applies to certain page types/views?
EpiServer will in edit mode always show the option of rendering "Test" even though it should only apply to a few pages in the CMS.