Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Drake 80 posts 318 karma points c-trib
    Sep 11, 2020 @ 18:55
    Mark Drake
    0

    I'm putting together a small demo but I've gone in circles trying to figure this out.

    Let's say I have Umbraco content nodes setup and working for an e-commerce site. There's a store root node, with a category, and a product node. And all these nodes have razor views, and if I go to any of the pages they look perfect.

    These pages actually exist in our Umbraco content structure:

    • Store
      • Category
        • Product

    But in reality, we have 100s of categories and products, and we are integrating with data off-platform. No worries, as we've hijacked the controller for each of these pages to return the data we need in our views.

    I tried following these instructions to generate routes such as store/games or store/games/game-title and inject (?) the proper content model.

    So I created myself a Composer and registered a simple route.

    RouteTable.Routes.MapUmbracoRoute(
        "NopRoutes-Category",
        "store/{category}",
        new
            {
                controller = "NopCatalogPage",
                action = "Category",
                category = "",
                template = "nopCatalogPage"
            },
            new ProductListingFilterHandler(category));
    

    Where category is the content node, in Umbraco, representing a category page.

    Requesting anything like "store/games" for instance will hit the same controller as "store/category". Content model looks the same.

    Except that I get an error message with my custom route:

    No physical template file was found for template Index

    Looks like the return CurrentTemplate() statement works if Umbraco is routing the page, but I'm lacking something in my custom route. Anyone care to venture a guess as to what I'm doing wrong on this end?

  • Marc Goodson 1625 posts 10767 karma points MVP 6x c-trib
    Sep 12, 2020 @ 07:07
    Marc Goodson
    1

    Hi Mark

    Would need to check this when I'm next at a computer but...

    is it because you are specifying a 'template' in the MapUmbracoRoute method?

    template = "nopCatalogPage"
    

    I don't remember ever doing that!

    Essentially I think CurrentTemplate should return the template that the content item for the request is published with, in your case this is the node that your VirtualNodeRouteHandler is returning.

    new ProductListingFilterHandler(category));
    

    So if you remove the explicit mention of 'template' in the MapUmbracoRoute, and you make sure your 'category' Document Type has a template assigned to it in Umbraco - then CurrentTemplate may return a valid template.

    If that doesn't resolve, and your ProductListingFilterHandler is definately returning the correct category node (set a breakpoint to see, before it blows up)

    Then you can also return a direct View instead of CurrentTemplate

    eg

    return View("~/views/nopCatalogPage.cshtml",yourViewModel);
    

    which at least might determine if the issue is in CurrentTemplate or in the mapping!

    regards

    marc

  • Mark Drake 80 posts 318 karma points c-trib
    Sep 23, 2020 @ 20:59
    Mark Drake
    0

    Thank you Marc. Sorry it's taken me so long to get back to this. You'd think with being stuck inside I'd have all the time in the world! Thank you again. I will look into this.

    I tried the template = "string" as a last ditch effort that made no difference. :)

  • Marc Goodson 1625 posts 10767 karma points MVP 6x c-trib
    Sep 23, 2020 @ 22:19
    Marc Goodson
    0

    Hi Mark

    What I mean is try without specifying a template at all in the mapping, as it's the Umbraco routing in the controller action that will determine the template based on the current associated IPublishedContent item (what the virtual node route handler returns).

    so

    RouteTable.Routes.MapUmbracoRoute(
        "NopRoutes-Category",
        "store/{category}",
        new
            {
                controller = "NopCatalogPage",
                action = "Category",
                category = UrlParameter.Optional
    
            },
            new ProductListingFilterHandler(category));
    

    If you are not sure the ProductListingFilterHandler is finding an IPublishedContent item which is published with a template, you could try temporarily 'hardcoding' the virtualnoderoutehandler to the id of a known published content category using the core UmbracoVirtualNodeByIdRouteHandler

    new UmbracoVirtualNodeByIdRouteHandler(1058)

    where 1058 would be the known id...

    ... not as a final solution but just to make sure you have a Published Content item with a template returned here.

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft