PiranhaCMS / piranha.core.docs

Official documentation for Piranha CMS
MIT License
12 stars 51 forks source link

Complete example of creating a new pagetype/archivetype #48

Open michaelrall opened 4 years ago

michaelrall commented 4 years ago

Hello,

I'm trying to create a custom archive + post type for a FAQ-Area on my site (razor pages). Following the docs I created a FAQArchive and an FAQPost

namespace landingpage.Models.PageTypes
{
    [PageType(Title = "FAQ Archive", UseBlocks = false, IsArchive = true)]
    public class FAQArchive : Page<FAQArchive>
    {
        public PostArchive<FAQPost> Archive { get; set; }
    }

    //var model = await api.Pages.GetByIdAsync<SimpleArchive>(id);
    //model.Archive = await api.Archives.GetByIdAsync<SimplePost>(...);
}
namespace landingpage.Models.PostTypes
{
    [PostType(Title = "FAQ Entry")]
    public class FAQPost : Post<FAQPost>
    {
    }
}

I can create a page with the FAQArchive-Type and add posts of type FAQPost - so far, so good.

Now when I navigate to the page (either preview or not) the page stays empty. I already tried to create a custom .cshtml file for my types but with no success.

So what is missing to complete my task ?? Do I need to setup some routing? Where would I place the view markup to have a custom rendering of my archive and its posts?

kind regards

tidyui commented 3 years ago

Hi there. By default all pages are routed to ~/page, all posts to ~/post and all archives to ~/archive. To add a specific route for a content type you either use the PageTypeRouteAttribute or PostTypeRouteAttribute. More information on this can be found in the documentation, here for page types: https://piranhacms.org/docs/content/pages