Copied to clipboard

Flag this post as spam?

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


  • Russell McGinnis 48 posts 183 karma points
    Jul 24, 2015 @ 16:36
    Russell McGinnis
    0

    Override default rendering of ParseInternalLinks

    I would like to override the default rendering of TemplateUtilities.ParseInternalLinks.

    When my editors are creating content in a Rich Text Editor, and adding links to other internal content the links are stored something like {link:nodeId} - when the text is rendered however it goes through TemplateUtilities.ParseInternalLinks to turn it into an a tag with the appropriate properties.

    Our content has varying levels of access associated with it. Instead of not showing users links that they cannot access, we want to show them the link, but if clicked pop up a modal explaining what they need to do to see the content.

    I think the best place to do this would be in ParseInternalLinks, however I cannot see any way to do this.

    Any ideas ?

    Thanks

  • Mike Chambers 636 posts 1253 karma points c-trib
    Jan 05, 2016 @ 16:06
    Mike Chambers
    0

    Did you find a way to override at source with out building you own dll's from the source code? (our requirement to manipulate is for a SPA which still uses the hierarchical approach in the admin)

    if using the grid, rte content here can be affected by modifiy the rte property editor..

    \Views\Partials\Grid\Editors\Rte.cshtml

    I just lifted the parseInternallinks from the source and redifined in this context.

    @model dynamic
    @using Umbraco.Web.Templates
    @using System.Text.RegularExpressions
    
    @*Html.Raw(TemplateUtilities.ParseInternalLinks(Model.value.ToString()))*@
    @Html.Raw(ParseInternalLinks(Model.value.ToString()))
    
    
    @functions{
    
        public string ParseInternalLinks(string text)
        {
            //TODO: Pass in an Umbraco context!!!!!!!! Don't rely on the singleton so things are more testable, better yet, pass in urlprovider, routing context, separately
    
            //don't attempt to proceed without a context as we cannot lookup urls without one
            if (UmbracoContext.Current == null || UmbracoContext.Current.RoutingContext == null)
            {
                return text;
            }
    
            var urlProvider = UmbracoContext.Current.UrlProvider;
    
            // Parse internal links
            var tags = Regex.Matches(text, @"href=""[/]?(?:\{|\%7B)localLink:([0-9]+)(?:\}|\%7D)", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
            foreach (Match tag in tags)
                if (tag.Groups.Count > 0)
                {
                    var id = tag.Groups[1].Value; //.Remove(tag.Groups[1].Value.Length - 1, 1);
                    var newLink = urlProvider.GetUrl(int.Parse(id)).TrimStart('/');
                    text = text.Replace(tag.Value, "href=\"/#" + newLink);
                }
    
            return text;
        }
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft