question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to create a new Page type in 8.3.0

See original GitHub issue

Hi,

I’ve just started playing around with Piranha CMS, which seems lika a rellay great CMS tool that I would like to use. After reading the docs I wanted to get a feeling of what it is like to use Piranha as a programmer and the first thing I wanted to try was to create a new Page type. But I am unable to get it to work!

I’m using the latest NuGet packages (8.3.0) and created a project using the piranha.razor template (after installing it with dotnet new -i Piranha.Templates as per the docs. I then made a copy of Models\StandardPage.cs and renamed the file to TestPage.cs:

using Piranha.AttributeBuilder;
using Piranha.Models;

namespace jonasblog.Models
{
    [PageType(Title = "Test page")]
    public class TestPage  : Page<TestPage>
    {
    }
}

I run in debug with Visual Studio 2019, add seed data and login in to the manager. In the manager I can select “Test page” when adding a new page. I add a title to the page and some blocks, saves and publishes. When I then go to the front page of the site I can see the newly created page in the menu, but when I click the link I get a 404 error. The URL matches the slug in the page settings URL segment.

If I do the same thing, but use Standard Page Type instead of my Test Page it works just fine!

In the docs it says that when creating a new page type, it should be added in the Configure method of the startup class using the PageTypeBuilder, but it also says that one could use the ContentTypeBuilder (new ContentTypeBuilder(api).AddAssembly(typeof(Startup).Assembly).Build().DeleteOrphans();) which is specified in the template. Is this not true, are the docs out of date? Is it possible to use both PageTypeBuilder and ContentTypeBuilder to get around this issue? If so, what order should the be added in?

I’m probably doing something wrong, but what? Since I can see the Page Type in the manager I’m guessing that the page type is added correctly, so I can’t be that far off.

Thanks in advance, and I hope this is the correct place to post this kind of question!

Hälsningar, Jonas

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
tidyuicommented, Jul 20, 2020

Hi there @jonaslorander! There’s nothing wrong with the page type itself, but you haven’t configured any routing for your new type. When a page matching the current request url is found by the middleware is found it’s routed to mvc/razor pages. The default route for pages is /page, but as you see by taking a look at ~/Pages/Page.cshtml (https://github.com/PiranhaCMS/piranha.core.templates/blob/master/src/web/razor/Pages/Page.cshtml) this expects a StandardPage as it’s model.

To fix this you need to send all requests to pages of your new type to another .cshtml page. This is done by adding the PageTypeRouteAttribute to your type, for example:

[PageType(Title = "Test page")]
[PageTypeRoute(Title = "Default", Route = "/test")]
public class TestPage  : Page<TestPage>
{
}

Then to serve the request you would add a page at ~/Pages/Test.cshtml. You can make a copy of ~/Pages/Page.cshtml, but remember to change the model type at the second line.

You can find more information about routing on the page under “Page Routing” https://piranhacms.org/docs/content/pages

0reactions
dinukasalcommented, Dec 7, 2020

@tidyui it was because my view filename was Contact.cshtml, when renamed to ContactPage.cshtml it workd. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues resolved in 8.3.0 | Confluence Data Center and ...
Key Summary Status CONFSERVER‑82851 Make View Macro excluded macro names pluggable Closed CONFSERVER‑40457 Add REST API endpoint for generating space exports Closed CONFSERVER‑36956 Ability to see...
Read more >
Unable To Create A New Attribute
I am brand new to creating attributes and variable products. I did manage to create ... The page I need help with: [log...
Read more >
Error while creating new React app ("You are running ` ...
Try running npx clear-npx-cache to clear your npx cache and then running the npx create-react-app your-app command.
Read more >
8.3.0 Release Notes - Concrete CMS Documentation
Fixed bug with uncaught exception in authentication types. Fixed: Adding a new page via the sitemap with a required user prevents the page...
Read more >
List of Changes for Quick Fields 8.3.0 Cumulative Hotfix ...
The PDF image page generation option now properly creates images for ... receive an "Unable to cast object of type ''iTextSharp.text.pdf.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found