Kentico 13 content tree based routing, match the same page type for different controller

Petro Solomchak asked on December 24, 2021 14:36

Is there a way to match another controller if the page's node alias contains some string? For example, any page(Some page type) will handle by OneController, but if pages of this page type are under some folder(for example with nodeAlias "Second") they will handle by SecondController

Recent Answers

Brenden Kehren answered on January 4, 2022 14:05

You'd need to create custom routes for this to happen. There are other alternatives too like creating a widget or creating another page type

0 votesVote for this answer Mark as a Correct answer

Sean Wright answered on January 4, 2022 23:59

What Brenden said is correct.

Xperience's Content Tree based routing routes pages of a given type to a specific Controller or View.

However, there's nothing preventing you from performing whatever logic you want in that Controller action and using the IPageDataContextRetriever to get access to the current Page (matched by route).

You can then find where it is in the Content Tree (what its parents Pages are) and make different db calls to get related data or render different Razor views, all dependent the details of the Page.

public void YourController : Controller
    public ActionResult Index()
        // ...

        if (something)
            return View("NormalView", pageData);
            return View("OtherView", customData);

If you really want to customize which Controller handles which specific Page based on slicing up the URL, you probably shouldn't be using Content Tree based routing.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.