Don't miss out Virtual Happy Hour today (April 26).

Try our conversational search powered by Generative AI!

Trying to create "folder/container page type"

Vote:
 

I'm trying to create a folder/container page type, one that has a folder as an icon in the node tree. My code looks like this for the page type class

 

[ContentType(DisplayName = "Folder page", GUID = "894f7fd4-9273-4335-aaef-0e3937ca5272", Description = "This page is a folder page to structure news better.")]
    [AvailablePageTypes(Include = new Type[] { typeof(NewsPage) } )]
    public class FolderPage : PageData
    {
        public override void SetDefaultValues(ContentType contentType)
        {
            base.SetDefaultValues(contentType);
            base.VisibleInMenu = false;
        }
    }


I have no controller and no view. When I add this to the node tree I get the page icon a the message saying EPi can't render the page since their is no view/controller and so on. What have I missed?

Thanks!
#77365
Nov 18, 2013 8:47
Vote:
 

Do you have a DefaultController registered for your page types? If you look at the Alloy Tech sample site you can see their approach there. Basically they use an interface to identify container pages and exclude them from the default rendering by their default controller.

Frederik

#77370
Nov 18, 2013 9:39
Vote:
 

This seems like over kill. I have added this (which works :) )

 

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class CustomizedRenderingInitialization : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            context.Locate.TemplateResolver()
                .TemplateResolved += TemplateCoordinator.OnTemplateResolved;
        }

        public void Uninitialize(InitializationEngine context)
        {
            ServiceLocator.Current.GetInstance<TemplateResolver>()
                .TemplateResolved -= TemplateCoordinator.OnTemplateResolved;
        }

        public void Preload(string[] parameters)
        {
        }
    }

    [ServiceConfiguration(typeof(IViewTemplateModelRegistrator))]
    public class TemplateCoordinator : IViewTemplateModelRegistrator
    {
        public static void OnTemplateResolved(object sender, TemplateResolverEventArgs args)
        {
            if (args.ItemToRender is FolderPage)
            {
                args.SelectedTemplate = null;
            }
        }

        public void Register(TemplateModelCollection viewTemplateModelRegistrator)
        {
            
        }
    }

 

But should I really need all that code for this? As far as I remember from the EPi-course they said all I needed to do was not create any cotnroller/view. This way EPi would understand itself it's a folder page. (Translated from webform, no template = folder page). Am I wrong here?

#77379
Nov 18, 2013 11:06
Vote:
 

No you´re right, this is the default behavior. But if you have setup a DefaultController to render all the page types by default then this will override the default built in EPiServer behavior.

Frederik

#77381
Nov 18, 2013 11:18
Vote:
 

I see, but I don't have any default controller so I shouldn't need this but still it only works when using this code. Do you have any idea what can cuase this behaviour? (a bit of question perhaps)

#77383
Nov 18, 2013 11:28
Vote:
 

If you make a request to

ServiceLocator.Current.GetInstance<EPiServer.DataAbstraction.TemplateModelRepository>().List(typeof(FolderPage)) 

what do you get back? It seems like there is some template that states that it can render FolderPage.

#77400
Nov 18, 2013 15:27
Vote:
 

Johan -> Thanks! Turns out I never thought of my previewcontroller. Think I stole the code from you Johan from a blog.

[TemplateDescriptor(Inherited = true, Tags = new string[] { RenderingTags.Preview })]
    public class PreviewController : ActionControllerBase, IRenderTemplate<IContentData>
    {
        public ActionResult Index(BlockData currentBlock)
        {
            if (currentBlock is HighlightBlock)
            {
                var currentHighlightBlock = currentBlock as HighlightBlock;
                return PartialView("/Views/Blocks/_HighlightBlock.cshtml", currentHighlightBlock);
            }
            else if (currentBlock is ContactBlock)
            {
                var currentContactBlock = currentBlock as ContactBlock;
                return PartialView("/Views/Blocks/_MajorContactBlock.cshtml", currentContactBlock);
            }

            return View(currentBlock);
        }
    }

This one is called upon if there is no other renderer. Removing this makes it possible for me to have a folder page without any code. So I need the extra code to make the page a folder page.

#77401
Nov 18, 2013 15:56
Vote:
 

You should be able to just change your preview controller to implement IRenderTemplate<BlockData> (instead of IRenderTemplate<IContentData>), my bad....

#77431
Nov 19, 2013 10:31
Vote:
 

Perfect, now I can skip the extra code. And I should know that without you pointing it out, stupd of me. It's not good to follow guides blindly and not thinking yourself :P

#77432
Nov 19, 2013 10:45
Vote:
 

Hi there! 

Does anybody know how to make the folder icon appear on tree? 

The page acts like a folder page (no url, no rendering) but the icon on the tree is still the one that ordinary pages use, so I don't know what I could be missing here. 
I tried your sugestion Johan, 

ServiceLocator.Current.GetInstance<EPiServer.DataAbstraction.TemplateModelRepository>().List(typeof(FolderPage))

and it returns count = 0, so everything looks right. I have no default controller in this project.

Any suggestions? 

/Kenia

#144147
Feb 08, 2016 15:28
Vote:
 

For the desired content types, inherit from an interface (I make it generic, in the below example IContainerPage). Add the below code to the project. Done :)

[UIDescriptorRegistration]
    public class ContainerPageUIDescriptor : UIDescriptor<IContainerPage>
    {
        public ContainerPageUIDescriptor()
            : base(ContentTypeCssClassNames.Container)
        {
            DefaultView = CmsViewNames.AllPropertiesView;
        }
    }
#144148
Feb 08, 2016 15:36
Vote:
 

Works like a charm!! Thanks Andreas :-) 

#144188
Feb 09, 2016 8:09
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.