Copied to clipboard

Flag this post as spam?

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


  • Thomas Ravnholt 12 posts 102 karma points
    Sep 29, 2022 @ 12:03
    Thomas Ravnholt
    0

    Fallback to ancestor + defaultvalue not working

    Hi.

    When using fallback to ancestor together with default value, i do not get any value in return, if there a value in one of the ancestors "resonOneTitle" field.

    But if i remove the value from all the ancestors, then i get the default value as expected.

    If i only call for the ancestor as fallback then it works perfectly, and returns the value from the first ancestor.

    The code is inside a partial containing:

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    @using Umbraco.Cms.Core.Models.PublishedContent;
    
    @Model.Value("reasonOneTitle", fallback: Fallback.To(Fallback.Ancestors, Fallback.DefaultValue), defaultValue: new HtmlString("Default page title"))
    

    If i do either of these, then it works just fine

    @Model.Value("reasonOneTitle", fallback: Fallback.ToAncestors)
    
    @Model.Value("reasonOneTitle", fallback: Fallback.ToDefaultValue, defaultValue: new HtmlString("Default page title"))
    
  • Huw Reddick 1932 posts 6722 karma points MVP 3x c-trib
    Sep 29, 2022 @ 13:07
    Huw Reddick
    101

    Your problem is this new HtmlString("Default page title") it should just be a string.

    @Model.Value("reasonOneTitle", fallback: Fallback.To(Fallback.Ancestors, Fallback.DefaultValue), defaultValue: "Default page title")
    
  • Thomas Ravnholt 12 posts 102 karma points
    Sep 30, 2022 @ 06:12
  • Huw Reddick 1932 posts 6722 karma points MVP 3x c-trib
    Sep 30, 2022 @ 06:32
    Huw Reddick
    1

    It would seem the doc is incorrect :D

    I ran a few tests and it only worked when I passed it a normal string.

  • Thomas Ravnholt 12 posts 102 karma points
    Sep 30, 2022 @ 06:49
    Thomas Ravnholt
    0

    Dammit! I was so frustrated yesterday xD

    Thanks for helping me out, yet again ;)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies