Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically add / for content type routes #1245

Closed
mkarlsson opened this issue Jun 22, 2020 · 4 comments
Closed

Automatically add / for content type routes #1245

mkarlsson opened this issue Jun 22, 2020 · 4 comments

Comments

@mkarlsson
Copy link

It goes to Page route in CMS controller and not the one I created (for department page). I read the route documentation and understood it like it will pick up the correct page type in the CMSCOntroller if I add the route value and Controller pagetype to the name of the pagetype?

Startup.cs
var pageTypeBuilder = new Piranha.AttributeBuilder.PageTypeBuilder(api) .AddType(typeof(Models.DepartmentPage)) .AddType(typeof(Models.StandardPage)) .AddType(typeof(Models.LanguageSelectorPage)); pageTypeBuilder.Build() .DeleteOrphans();

CMSController
`[Route("department")]
public async Task DepartmentPage(Guid id)
{
var model = await _api.Pages.GetByIdAsync(id);

        return View(model);
    }`

DepartmentPage.cs (actually empty...)
`[PageType(Title = "Department page")]
public class DepartmentPage : Page
{
///


/// Gets/sets the available populareCategories
///

//public IEnumerable PopulareCategories { get; set; } = new List();

}`

Then I have a DepartmentPage.cshtml in VIews/CMS..

image

Also, regarding the routing logic its hard to understand how I can create a english page and a Swedish page and use the same route?

@tidyui
Copy link
Member

tidyui commented Jun 23, 2020

Hi there! The route needs to start a forward slash, so department should be /department. We've talked about fixing this when types are imported as it's easy to forget and easy to fix.

@tidyui tidyui changed the title Can't get routing to new pagetype working Automatically add / for content type routes Jun 23, 2020
@magnuskarlssonhm
Copy link

Thanks, quick as usual!

Added it but it still goes to Page route. Using the latest template.
dotnet new piranha.mvc -s BlobStorage -d SQLServer
Here is the page route in the template, it does not have a forward slash, am I misunderstanding something here?

[Route("page")] public async Task<IActionResult> Page(Guid id, bool draft = false) { try

@tidyui
Copy link
Member

tidyui commented Jun 23, 2020

No, the route on the Page Type. I misread you code and thought you'd added one. The route in the controller should probably be without a forward slash. But on each page type that you need to send to a different route you have to add a PageTypeRouteAttribute

[PageType(Title = "My Page")]
[PageTypeRoute(Title = "Default", Route = "/myroute")]
public MyPage : Page<MyPage>
{
}

Regards

@tidyui tidyui added this to the Version 8.4 milestone Jun 23, 2020
@tidyui tidyui self-assigned this Jun 23, 2020
@tidyui tidyui closed this as completed in 9964c49 Jun 23, 2020
@mkarlsson
Copy link
Author

mkarlsson commented Jun 23, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants