Copied to clipboard

Flag this post as spam?

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


  • Jeroen Oostwouder 63 posts 159 karma points
    Jul 22, 2016 @ 09:06
    Jeroen Oostwouder
    1

    Default Umbraco field fallback not working?

    The Vorto pages says:

    To retrieve the values, Vorto comes with a few handy IPublishedContent extension methods (sorry, no dynamics support yet) namly HasVortoValue and GetVortoValue. These can be used as direct replacements to the built in HasValue and GetPropertyValue methods that come with Umbraco (if the value you are after isn't a Vorto value, it defaults back to the Umbraco implementation).

    So, I wanted to test this, and made a default textstring property (alias: "test") on a page. The result of the following code:

    var page = Umbraco.TypedContent(1107);
    var x = t.GetVortoValue("test");
    

    is a null value. I was expecting the value of the textbox. What am I doing wrong?

    Umbraco: 7.4.3 Vorto: 1.5.2

  • Jack Penney 1 post 22 karma points
    Nov 18, 2016 @ 16:40
    Jack Penney
    1

    Hey,

    I'm also getting a similar problem, I'm running on Umbraco 7.5.3 and Vorto 1.5.3

    If i run the following code

    var vortoValue = Model.Content.GetVortoValue<string>("nonVortoTextstring");
    var propValue = Model.Content.GetPropertyValue<string>("nonVortoTextstring");
    

    vortoValue comes back as null while propValue gives me the textstring value

    I would have assumed GetVortoValue() would default to the property value if it found the datatype doesn't use Vorto. When I use GetVortoValue() on Vorto dataypes within the same template it pulls out the content just fine, so I don't think its a setup issue.

    For the time being I've created a little extension method so it falls back on the property value, not perfect but it does the trick:

    public static class IPublishedContentExtensions
    {
        public static T GetVortoOrPropertyValue<T>(this IPublishedContent model, string propertyName)
        {
            T returnValue;
    
            if (model.HasVortoValue(propertyName))
            {
                returnValue = model.GetVortoValue<T>(propertyName);
            }
            else
            {
                returnValue = model.GetPropertyValue<T>(propertyName);
            }
    
            return returnValue;
        }
    }
    
  • Ali Sheikh Taheri 469 posts 1645 karma points c-trib
    Jan 12, 2017 @ 22:30
    Ali Sheikh Taheri
    0

    Hi Guys,

    I had the same issue with the Textboxes, Nested Content and Rich Text editor.

    Jack your trick did the work, Thanks for sharing it.

    Cheers

    Ali

Please Sign in or register to post replies

Write your reply to:

Draft