Copied to clipboard

Flag this post as spam?

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


  • Anders Smedman 9 posts 30 karma points
    Jun 07, 2016 @ 09:17
    Anders Smedman
    0

    Shared content between Root content nodes with correct Url

    Hi! I built a few ordinary CMS sites in Umb 6/7 the past 2 years, simple ones with docTypes and Templates with basic addressing content pages of docType to iterate childrens as lists, navbars and content. Often just by using the editors inside Umbraco.

    Now I am developing and mulit-lingual site with shared root content :

    www
        -- se
        ---- Produkter
        -- en
        ---- Products
    ProductDatabase
        -- Categories
        ---- IndustriPC
        ------ Panel PC
        ------ Box PC
        -- Products
        -- Filters
        -- Manufacturers
    

    The Produkter/Products, doctype: ProductStart, has an contentPicker which I set to below ProductDatabase>Categories

    The site will have a shared node we call "Product Database".

    The problem now, how can I fix som the category node Panel PC under the en node of the site get URL like below?

    /en/products/industripc/boxpc
    

    I am currently playing with UrlProvider and ContentFinder but when the UrlProvider kicks in and I try to get the Url I want to change the W3P process crashes in IIS. I compile the project to an IIS 7.5 (Win2008R2 server).

    Note: If I change the content.Url to content.Parent.Url it seems to work but I have no use of that, just tried to see.

    The UrlProvider code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Threading.Tasks;
    using extend.logic.Utilities;
    using Umbraco.Web;
    using Umbraco.Web.Routing;
    
    namespace extend.logic.UrlProvider
    {
        public class CategoryUrlProvider : BaseClass, IUrlProvider
        {
            public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
            {
    
                var content = umbracoContext.ContentCache.GetById(id);
    
                if (content != null && content.DocumentTypeAlias == "dtCategory")
                {
    
                    var url = content.Url;
    
                    return url;
    
                }
                return null;
            }
    
            public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
            {
                return Enumerable.Empty<string>();
            }
        }
    }
    

    I register it with

    namespace extend.logic.Events
    {
        public class UmbracoEvents : ApplicationEventHandler
        {
            protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
    
                UrlProviderResolver.Current.InsertTypeBefore<DefaultUrlProvider, CategoryUrlProvider>();
    
            }
        }
    }
    

    Am I on the right track here? What is the best practise when you want to create a "BackOffice Admin Database" and then "pull" the data from the actual site/CMS to display it, and have the correct inherited urls as a combination of the CMS page and the BackOffice node.

    Anyone know if theres a complete kit to download, source code and all that I may study and understand how to do this.

    Feels I am walking in circles.

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jun 07, 2016 @ 10:19
    David Brendel
    0

    Hi Anders,

    have you seen this article: http://24days.in/umbraco/2014/urlprovider-and-contentfinder/

    It is quite helpfull with the Provider and Finder.

    I also used them for changing some urls but can't access my code right now, so will see if I can add it later.

    The crashing hasn't occured for me.

    Regards David

  • Anders Smedman 9 posts 30 karma points
    Jun 07, 2016 @ 13:13
    Anders Smedman
    0

    Hi David!

    Thanks, yes, it is that article I based the implementation on. I am pretty sure I have som kind of recursive problem to get content.Url. I actually found logs in the Windows App log that says the nlssorting.dll crash. Digging more.

    But at the same time, all snippets and examples I see shows how the get the parent url

    var url = content.Parent.Url
    

    But that i useless in my case.

    Maybe I am thinking wrong? What I am trying to acheive:

    Trigger the UrlProvider on Document Type which works with a crash as result! :)

    Get the Url and somehow create a new one based on:

    a) The page that "hold" my category = /en/products
    b) Combine above while iterating ProductDatabase Categories to create a nav as <ul><li> and that to create a new Url
    

    So the result I am trying for should be like: /en/products + /industripc/panelpc

    Is this correct approach?

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jun 08, 2016 @ 10:39
    David Brendel
    0

    Hi Anders,

    have you tried to just add a dummy string as the url to see if that works?

    Sadly I hadn't time to dig for the xode where I used the url provider.

    I'm also not quite sure if you need the url provider at all. When you just build the url in your navigation based on convention and the categorie names a content finder is sufficient or?

    Regards David

  • Anders Smedman 9 posts 30 karma points
    Jun 08, 2016 @ 10:55
    Anders Smedman
    0

    Hi David,

    Yes, the UrlProvider "works" if I return like .UrlName or "/test-url/".

    So, if i in my ordinary template.cshtml for /en/products do something like (from my head, mispelling may occur):

    var currentUrl = HttpContext.Current.Request.Url.AbsoluteUri.ToString()
    // currentUrl should be /en/products
    
    var pdCats = CurrentPage.AncestorOrSelf(1).Descendents("dtCategory")[0];
    // pdCats should be the ProductDatabase > Categories node
    
    foreach(var c in pdCats.Children)
    {
    var combinedUrl = String.Concat(currentUrl, c.Url.ToString()).Replace("categories/", string.Empty);
    <li>
       <a href="@combinedUrl">@c.Name</a>
    </li>
    }
    

    I should get /se/products/industripc for the first iterade pdCats.Children

    Then I "only" have to focus on a ContentProvider to "resolve" the combinedUrl to correct category node? What do I need to "view" the result/target url? I guess I need some kind of template in /en/products structure which somehow loads the node id and present the category data, and maintain the Layout Master.cshtml and inheritance from /se and "down" the structure.

    Thanks a bunch! :)

Please Sign in or register to post replies

Write your reply to:

Draft