Try our conversational search powered by Generative AI!

Display mode/channel per pagetype

Vote:
 

If I register a customer display mode like this:

DisplayChannelService channelSvc = context.Locate.DisplayChannelService();
channelSvc.RegisterDisplayMode(new DefaultDisplayMode("Test")
{
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.

 

 

#62992
Nov 06, 2012 13:20
Vote:
 

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.

#62996
Nov 06, 2012 15:35
Vote:
 

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.

#62998
Nov 06, 2012 15:58
Vote:
 

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.

#63051
Nov 08, 2012 7:47
Vote:
 

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?

#63053
Nov 08, 2012 10:06
Vote:
 

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:

using System.Linq;
using System.Web;
using EPiServer.ServiceLocation;
using EPiServer.Templates.Alloy.Business.Channels;
using EPiServer.Templates.Alloy.Models.Pages;
using EPiServer.Web;

namespace EPiServer.Templates.Alloy.Views.Pages
{
    public partial class StartPageTemplate : SiteTemplatePage<StartPage>
    {
        private readonly DisplayChannelService _displayChannelService;

        public StartPageTemplate()
            : this(ServiceLocator.Current.GetInstance <DisplayChannelService>())
        { }

        public StartPageTemplate(DisplayChannelService displayChannelService)
        {
            _displayChannelService = displayChannelService;
        }

        public bool IsMobileActive
        {
            get
            {
                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"%>

#63068
Nov 08, 2012 13:45
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.