Copied to clipboard

Flag this post as spam?

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


  • ianhoughton 233 posts 418 karma points c-trib
    Jan 08, 2016 @ 09:33
    ianhoughton
    0

    Remove segment from URL

    I have this structure on my site:

    structure

    and I'm trying to remove Convenience and Pharmacy from the url structure.

    I've created a custom URL provider:

    public class CustomUrlProvider : DefaultUrlProvider
    

    { public override string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode) { var home = new UmbracoHelper(UmbracoContext.Current).TypedContentAtRoot().First(x => x.DocumentTypeAlias.Equals("HomePage")); var categories = home.Children.Where(x => x.DocumentTypeAlias.Equals("CategoryPage"));

      foreach (var category in categories)
      {
          if (base.GetUrl(umbracoContext, id, current, mode).Contains(category.Url))
          {
              return base.GetUrl(umbracoContext, id, current, mode).Replace(category.Url, "/");
          }
          return base.GetUrl(umbracoContext, id, current, mode);
      }
      return base.GetUrl(umbracoContext, id, current, mode);
    

    } }

    and a custom ContentFinder:

    public class CustomContentFinder : IContentFinder
    

    { public bool TryFindContent(PublishedContentRequest contentRequest) { if (contentRequest != null) { // copy ContentFinderByNiceUrl but add your prefix back where it's missing const string PREFIX = "/convenience";

            string route;
            if (contentRequest.HasDomain)
              route = contentRequest.Domain.RootNodeId + PREFIX + DomainHelper.PathRelativeToDomain(contentRequest.DomainUri, contentRequest.Uri.GetAbsolutePathDecoded());
              else
                route = PREFIX  + contentRequest.Uri.GetAbsolutePathDecoded();
    
            contentRequest.PublishedContent = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetByRoute(route);
        }
    
        return contentRequest.PublishedContent != null;
    }
    

    }

    The problem is, the URLprovider gets itself in a constant loop when comparing the category.Url with the current node Url, and the ContentFinder is using magic strings instead of looking up the CategoryPage.

    Is there a better way of doing it, should I be looking at a Custom Segment provider instead?

  • TheOriginal 22 posts 122 karma points
    Jan 13, 2016 @ 14:03
    TheOriginal
    0

    If you are trying to hide it from a dynamic navigation, you can do it by checking it "hide from navigation". This is in the following path:

    Content:

    1. select page you want to hide
    2. go to properties tab
    3. Scroll down until you see a check box that's called "hide from navigation"

    That should hide it from the navigation bar but if i have miss understood the question, please respond and i'll try to help where i can.

  • Dennis Aaen 4427 posts 17860 karma points admin hq c-trib
    Jan 13, 2016 @ 14:09
    Dennis Aaen
    0

    Hi ianhoughton,

    Perhaps this post from the Umbraco advent calendar from 2014 can help you to archive what you are trying to, regarding to modify the URL

    http://24days.in/umbraco/2014/urlprovider-and-contentfinder/

    As you can see Jeroen is also talks about the Hybrid framework which you can find here. https://our.umbraco.org/projects/developer-tools/hybrid-framework-for-umbraco-v7/

    Hope this helps,

    /Dennis

  • Simon Dingley 1385 posts 3236 karma points c-trib
    Oct 05, 2017 @ 11:02
    Simon Dingley
    0

    Did you get this working?

    The problem is, the URLprovider gets itself in a constant loop when comparing the category.Url with the current node Url

    It will and you will eventually crash your application pool because you have an infinite loop when using the .Url property. Instead try using

    umbracoContext.ContentCache.GetRouteById(id)
    

    Hope that helps as I just got caught by the same issue.

    However, overcoming this issue presented another problem as I've detailed here.

Please Sign in or register to post replies

Write your reply to:

Draft