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
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?
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
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)
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.
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.
You should be able to just change your preview controller to implement IRenderTemplate<BlockData> (instead of IRenderTemplate<IContentData>), my bad....
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
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
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; } }
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