Copied to clipboard

Flag this post as spam?

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


  • Brady 6 posts 76 karma points
    Jun 29, 2016 @ 23:15
    Brady
    0

    LeBlender Property Issue

    I attempted to add a new text-string property to an existing Grid Editor. I am able to add the property just fine and see that the property was added when editing the Grid Editor properties & within the Content section. However I am having an issue accessing the new property.

    I am receiving this error on the front end where my Grid Editor should be rendering:

    Object reference not set to an instance of an object.

    Here is the snippet where I am attempting to access my new property and get the value:

    var trackingEvent = item.GetValue("trackingEvent");

    I have tried several different ways to grab this value. It seems like LeBlender does not recognize my new property even though I am able to see it within the Developer and Content sections.

    I initially thought I was receiving the object reference error because all of my grid editors now had a new property with an empty or null value. I tried to run some if else logic past it to check but I am unable to resolve this error. It seems like my new property is not being stored somewhere?

    I've hit a wall. What am I missing? Thanks in advance for any input!

  • Ian 178 posts 752 karma points
    Jun 30, 2016 @ 14:38
    Ian
    0

    can you post code which shows this line in a wider context as I don't think that line alone would produce an object reference error. Namely I would be interested in where 'item' is defined as that would be more likey but without seeing I could be wrong

  • Brady 6 posts 76 karma points
    Jun 30, 2016 @ 15:11
    Brady
    0

    Sure! Here is the code in full context:

    @inherits UmbracoViewPage<Lecoati.LeBlender.Extension.Models.LeBlenderModel>
    
    @if (Model.Items.Any()) {
    
        foreach (var item in Model.Items) {
        var ctaCopyArticle = item.GetValue<dynamic>("ctaCopyArticle");
        var ctaLinkArticle = item.GetValue<dynamic>("ctaLinkArticle");
        var trackingEvent = item.GetValue("trackingEvent");
    
        <div class="base call-to-action">
            <div class="overlay"></div>
            <div class="details">
                @if (@item.GetValue("ctaIconArticle") != null) {
                <i class="@item.GetValue("ctaIconArticle")"></i>
                }
                <h3>@item.GetValue("ctaTitleArticle")</h3>
                @Html.Raw(ctaCopyArticle)
                @if (ctaLinkArticle != null) {
                <p><a href="@ctaLinkArticle.url" target="@ctaLinkArticle.target" class="filled button" onclick="@trackingEvent">@ctaLinkArticle.name</a></p>
                }
            </div>
        </div>
        }
    }
    

    I should also note that I have tried getting the value using

  • Ian 178 posts 752 karma points
    Jul 01, 2016 @ 10:51
    Ian
    0

    looking at that it doesn't make much sense why you would get an error is if you put a break point I'm assuming its on that very line that it throws an exception?

    What happens if you put this on the line before and step into a breakpoint there?

    bool hasTrackingEvent = item.HasProperty("trackingEvent");
    
  • Brady 6 posts 76 karma points
    Jul 06, 2016 @ 06:16
    Brady
    0

    Hey Ian,

    I am receiving this error:

    error CS1928: 'Lecoati.LeBlender.Extension.Models.LeBlenderValue' does not contain a definition for 'HasProperty' and the best extension method overload 'umbraco.ContentExtensions.HasProperty(umbraco.cms.businesslogic.Content, string)' has some invalid arguments

    With this code:

    @inherits UmbracoViewPage<Lecoati.LeBlender.Extension.Models.LeBlenderModel>
    
    @if (Model.Items.Any()) {
    
        foreach (var item in Model.Items) {
        var ctaCopyArticle = item.GetValue<dynamic>("ctaCopyArticle");
        var ctaLinkArticle = item.GetValue<dynamic>("ctaLinkArticle");
        bool hasTrackingEvent = item.HasProperty("trackingEvent");
        var trackingEvent = item.GetValue("trackingEvent");
    
        <div class="base call-to-action">
            <div class="overlay"></div>
            <div class="details">
            @item.GetValue("trackingEvent");
                @if (@item.GetValue("ctaIconArticle") != null) {
                <i class="@item.GetValue("ctaIconArticle")"></i>
                }
                <h3>@item.GetValue("ctaTitleArticle")</h3>
                @Html.Raw(ctaCopyArticle)
                @if (ctaLinkArticle != null) {
                <p><a href="@ctaLinkArticle.url" target="@ctaLinkArticle.target" class="filled button" onclick="@trackingEvent">@ctaLinkArticle.name</a></p>
                }
            </div>
        </div>
            }
        }
    
  • Ian 178 posts 752 karma points
    Jul 06, 2016 @ 07:53
    Ian
    0

    Not sure what version of leblender you are using but if you see here the latest version does have hasproperty https://github.com/Lecoati/LeBlender/blob/master/Src/Lecoati.LeBlender.Extension/Models/LeBlenderValue.cs

  • Brady 6 posts 76 karma points
    Jul 08, 2016 @ 18:57
    Brady
    0

    Current version is 1.0.8.4. I reinstalled the package and that fixed the HasProperty issue.

    I logged in to my sites Umbraco admin area and under the Developer section I looked at the XML Cache Data. The 'Content in the cmsContentXml table' had an error. I ran the Fix and that seems to have fixed all of my issues. I am able to run the snippet of code you provided and my grid editors are now rendering properly on the front end.

    You can consider the issue closed. Thank you for your time and effort it is much appreciated!

Please Sign in or register to post replies

Write your reply to:

Draft