localLinks in RTE content not resolving in View
# help-with-umbraco
b
I've just started a new Umbraco 14 site and am fairly new to Umbraco development. I've got a basic content type with a RTE field and am displaying that content in the associated view. Links created in the RTE to other pages are rendered as "/{localLink:3032aafe-bc49-4856-b067-1af894f8a7b2}" instead of the external URL. I found some posts referring to the use of HtmlLocalLinkParser and tried using its EnsureInternalLinks method on the value before displaying it, but nothing changed. The documentation also seems to indicate that this shouldn't be necessary. So I've tried: // with untyped model Model.Value("content") // strongly typed model Model.Content.ToHtmlString() // using HtmlLocalLinkParser var linkParser = new HtmlLocalLinkParser(_umbracoContextAccessor, _publishedUrlProvider); var content = linkParser.EnsureInternalLinks(content, false); Any clues what I'm missing here?
j
I have a feeling something has changed in the local links. Usually they have the GUID without the hyphens (which is what is usually used for UDIs) and they also have a
data-udi
attribute on the link that should have the udi in it (something like
umb://document/4fed18d8c5e34d5e88cfff3a5b457bf2
- see https://docs.umbraco.com/umbraco-cms/reference/querying/udi-identifiers). Does the
a
have that attribute on it? If so, does the GUID have hyphens? Those may be the root of the issue.
d
I wonder if that is worth checking in V13 for comparison. Also brings up the question should someone new to Umbraco be using V14? I'm not advocating either way, I can see pros and cons with either. However, the next LTS is V17 and many suggest sticking with LTS for production.
j
I know they’re not hyphenated in v13 as I was just working on a v13 site and they use the UDI structure that matches the documentation I linked. But comparing the methods between the versions is a great idea
b
There is no data-udi attribute on the rendered link. I'll try it with v13. I am using v14 as it's what I got when following the setup/install documentation. 🤷‍♂️
I installed 13.4 and ran into this problem: https://discord-chats.umbraco.com/t/22310681/umbraco-13-fresh-install-not-installing but was able to get past it using unattended install. The links work in v13. Should I post an issue about this on Github? Seems odd nobody would have noticed this before.
j
b
Yeah, that looks like it. Not sure why I didn't find that when searching yesterday.
j
so there is a PR being reviewed that should fix it, we are trying to get it in to 14.1
d
Greetingz ... is there a link to that PR to know if the PR got merged? Ran into the same problem and am unable to find a workaround (without string-parsing) ... I updated my local version to 14.1.1, but doesnt seem to have changed
j
This is the PR and it appears to have been merged: https://github.com/umbraco/Umbraco-CMS/pull/16661
You can find it by looking at the issue as well
d
ok ... so it's in 14.2 sais the label .... thanks for the link ... do you know if this is "just" the backend handling (as the name of the issue sais) or if helpers for razor then also return the updated link?
j
Not sure! I didn’t dig into it 😅
d
I looks like it shouldbe in there ... but I still get links like this: href="/{localLink:435977bc-9ca7-403c-84b7-3b67eb3ab5ea}" ... Google sais I should use "TemplateUtilities" but I do not have this class anywhere in the assemblies... Any suggestions how to parse them correctly?
j
I have a client who does some... interesting things with content and writing their own raw HTML, so we wrote a helper to for v13 that uses core functionality to do this. I don't know for sure if it will work in 14.2 but it's worth a try 🙂
Copy code
public class StringHelper
{
    private readonly IUmbracoContextAccessor _contextAccessor;
    private readonly IPublishedUrlProvider _urlProvider;

    public StringHelper(IUmbracoContextAccessor contextAccessor, IPublishedUrlProvider urlProvider)
    {
        _contextAccessor = contextAccessor;
        _urlProvider = urlProvider;
    }

    public string? ParseLocalLinks(string? rawHtml)
    {
        if(rawHtml == null) return null;

        var linkParser = new HtmlLocalLinkParser(_contextAccessor, _urlProvider);
        var content = linkParser.EnsureInternalLinks(rawHtml, false);

        return content;
    }
}
Then in the View we use
Copy code
@inject YourProject.StringHelper _stringHelper;
@{
    var rawHtml = _stringHelper.ParseLocalLinks(Model.RichTextEditorContent);
}
d
Hey @Janae ... thx for the hint ... for a second I thought it works (code compiles - just had to inject stringhelper in Program.cs - ... but the links still dont get resolved ... Meanwhile I have the impression that my links are wrong ... if I select a file in the richtext-editor to link to I get a link rendered that looks like this: <a rel="noopener" type="media" href="/{localLink:c62e9421-9ca5-4b9f-85bf-bb86e663d84e}" target="_blank"... Shouldnt there be a segment like "umb:" in the link?
j
Yep, I just checked! My local link hrefs look like this:
href="/{localLink:umb://document/808c3622feda4c239c26d034d0262dd4}"
d
That is strange ... I removed the link and put it again in there ... still the same ... then obv. my installation has an issue ... i just got "/{localLink:c0e62ba0-e858-427f-bbb1-54e1f4e0962d}" ... well ... not good (for me :-D)
178 Views