Piranha.core: Dynamic Content from URL

Created on 18 Jan 2019  路  4Comments  路  Source: PiranhaCMS/piranha.core

Hello @tidyui !

I know that are busy right now, since you haven't answered my previous question, but when you have time - I will be glad to see your answer on this.

I need a dynamic page, with dynamic content. The URL should always be different (using a unique ID; maybe as parameter?), but the page template will be the same.

The page will load queried data from a database, but I have problem with understanding how this is going to work. If this helps, imagine it as a youtube video, having the same page layout, but loading different content everytime with a unique ID.

I am trying my own way at the moment, but I thought that is was worth asking you about this.

Yours,
Chris

question

Most helpful comment

Oh wow!

That's exactly what I needed!

Thank you for the quick reply,
Chris

All 4 comments

Hello!

I think you could achieve this using the PageTypeRoute attribute on your page model.

Our page model

[PageType(Title = "Video page")]
[PageTypeRoute(Title = "Default", Route = "/video")]
public class VideoPage : Page<VideoPage>
{

}

Our action method in our controller

[Route("video")]
[Route("video/{videoId}")]
public IActionResult Video(Guid id, string videoId)
{
    var model = api.Pages.GetById<VideoPage>(id);
    return View(model);
}

Here I added two routes as an example.
With the route [Route("video")] the videoId parameter will be populated using the URL:
~/video-page-slug?videoId=1234

But with the other route ([Route("video/{videoId}")]) we can instead use the URL:
~/video-page-slug/1234

BR
Filip

I'm reopening this with the documentation label so we'll remember to clarify this in the docs :)

Oh wow!

That's exactly what I needed!

Thank you for the quick reply,
Chris

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aneff-official picture aneff-official  路  6Comments

SamBray picture SamBray  路  3Comments

jcphlux picture jcphlux  路  4Comments

peppelorum picture peppelorum  路  3Comments

MehranDHN picture MehranDHN  路  3Comments