Copied to clipboard

Flag this post as spam?

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


  • Qamar Ali 34 posts 165 karma points
    Nov 10, 2021 @ 21:38
    Qamar Ali
    0

    Point sub-menu page to external URL

    Hello, On the main menu of my website , I have a page that has sub menus. I want to point the sub menu tab to an external URL. I used the below link to change the URL of the sub menu page but it does not work :

    https://our.umbraco.com/Documentation/Reference/Routing/routing-properties

    The link does help me to change the URL of my page but it does not let my sub menu page point to an external URL

    Below picture shows what I am trying to do :

    enter image description here

    I am trying to point the sub-menu page "Power Engineer/Inspector Login" to an external link i.e. https://apecsonline.absa.ca/Account/Login

    Can this be done on umbraco version 7.12.1 ?

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Nov 11, 2021 @ 07:26
    Bjarne Fyrstenborg
    0

    Hi Qamar

    There are different ways to solve this, but what I tend is creating implementing af custom IUrlProvider:

    public class ExternalUrlProvider : IUrlProvider
    {
        public IEnumerable<UrlInfo> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
        {
            return Enumerable.Empty<UrlInfo>();
        }
    
        public UrlInfo GetUrl(UmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current)
        {
            if (content is ContentModels.ExternalPage page)
            {
                var externalUrl = page.ExternalUrl;
    
                if (string.IsNullOrWhiteSpace(externalUrl)) return null;
    
                    return new UrlInfo(externalUrl, true, culture);
                }
    
                return null;
            }
        }
    }
    

    In this case I have a custom External Page (externalPage) document type and the ExternalPage class is generated by ModelsBuilder.

    Furthermore I have an extension method:

    public static class PublishedContentExtensions
    {
        public static bool IsExternal(this IPublishedContent content)
        {
            return content is ContentModels.ExternalPage;
        }
    }
    

    so in navigation you can do something specific with this page type:

    <a href="@menuItem.Url()" target="@(menuItem.IsExternal() ? "_blank" : "_self")" rel="@(menuItem.IsExternal() ? "noopener" : null)">@menuItem.Name</a>
    

    There are some documentation here regarding IUrlProvider: https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/outbound-pipeline-vpre81 but should also be available in v7: https://24days.in/umbraco-cms/2014/urlprovider-and-contentfinder

  • Qamar Ali 34 posts 165 karma points
    Nov 12, 2021 @ 15:12
    Qamar Ali
    0

    Hi Bjarne, Thank you for the solution but is there any other way I can do this? I mean directly from the front end ? In the "Properties" section, I found an Alternative URL section. It is using the UmbracoURlAlias . I tried entering my external link there but that did not help either :

    enter image description here

    Is there something I can do directly from the front end side ?

  • carl 12 posts 81 karma points
    Dec 07, 2021 @ 04:30
    carl
    0

    Were you able to figured this out? I'm currently stuck on this too

Please Sign in or register to post replies

Write your reply to:

Draft