+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / sfref appearing in hyperlinks

sfref appearing in hyperlinks

6 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    02 Nov 2010
    Link to this post
    Hi,

    I've got a control that is using generic content. When the content is displayed on the front-end website the links are rendered using:

    this.litText.Text = String.Format("<p class=\"marginBottomNone darkGrey\">{0}</p>", (this.bolShowLinkArrow == true) ? LinkParser.ResolveLinks(this.strContent.Replace("<a", "<a class=\"blue dottedUnderline dottedUnderlineBlue iconArrowUniversal\""), this.ResolveItemUrl) : LinkParser.ResolveLinks(this.strContent, this.ResolveItemUrl));

    private string ResolveItemUrl(string provider, Guid id, bool resolveAsAbsoluteUrl) {
        if (ContentManager.Providers.ContainsKey(provider)) {
            IContent cnt = ContentManager.Providers[provider].GetContent(id);
            if (cnt != null)
                return this.ResolveUrl(cnt.UrlWithExtension.ToLower());
        } else {
            SiteMapNode node = SiteMap.Provider.FindSiteMapNodeFromKey(id.ToString());
            if (node != null)
                return this.ResolveUrl(node.Url.ToLower());
        }
        return String.Concat("Item not found: [", provider, "]", id);
    }

    The links render correctly, i.e. they point to the correct page - however the attribute sfref is still showing in the code which is obviously invalid html. How do i remove this?

    Regards,
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Nov 2010
    Link to this post
    Hello higgsy,

    LinkParser.ResolveLinks has an overload where you can pass a boolean type parameter - preserveOriginalValue - If false the original value of altered attributes is not preserved in additional attribute named sfref.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    03 Nov 2010
    Link to this post
    Hi Ivan,

    Ok how does that work then. The code I'm currently calling is:

    LinkParser.ResolveLinks(this.strContent.Replace("<a", "<a class=\"blue dottedUnderline dottedUnderlineBlue iconArrowUniversal\""), this.ResolveItemUrl), @"<([/]?[p])>", String.Empty) : Regex.Replace(LinkParser.ResolveLinks(this.strContent, this.ResolveItemUrl

    To override the method using preserveOriginalValue needs the following parameters:

    public static string ResolveLinks(string html, GetItemUrl itemUrl, ResolveUrl resolveUrl, bool preserveOriginalValue);

    I presume this is the method you are suggesting I use? 

    I already have a ResolveUrl method, but what should GetItemUrl return? Is there a method for this?

    Thanks
    higgsy


  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    03 Nov 2010
    Link to this post
    Hi higgsy,

    GetItemUrl is a delegagete - GetItemUrl(string provider, Guid id, bool resolveAsAbsoluteUrl)

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    03 Nov 2010
    Link to this post
    Ivan,

    I am calling:

    LinkParser.ResolveLinks(this.strContent.Replace("<a", "<a class=\"blue dottedUnderline dottedUnderlineBlue iconArrowUniversal\""), this.ResolveItemUrl, null, false, false)

    And the sfref is still showing. I am using this code on the front-end control which is displaying the HTML - correct?

    Thanks
    higgsy
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    03 Nov 2010
    Link to this post
    Hi higgsy,

    Here is how you should call LinkParser.ResolveLinks

    text = LinkParser.ResolveLinks(text, ContentManager.ResolveItemUrl, null, false, false);

    Another option is using String.Remove to delete the sfref attribute.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
6 posts, 0 answered