Copied to clipboard

Flag this post as spam?

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


  • John Churchley 272 posts 1258 karma points c-trib
    Jun 03, 2014 @ 22:45
    John Churchley
    0

    Nodefactory .GetProperty() overload question

    I using Nodefactory to obtain values in a class I'm trying to workout if the .getProperty method has an overload that will allow me to set a value if the property is empty. Also is Nodefactory what I should be using with V7?

    Can someone give a short explination on how you on the method .GetProperty(string alias, out bool propertyExist) overload. I understand the alias would be the docucement type field alias however I don't understand the "out bool propertyExist" element.

    Thanks in advance

    see below for what I am attempting to simplify

    var node = new Node(1076);
    string preheadercontent = "";
    if (!Object.ReferenceEquals(node.GetProperty("preheadercontent"), null))
    {
          preheadercontent = node.GetProperty("preheadercontent").ToString();
    }            
    template = template.Replace("[preHeaderContent]", preheadercontent);
  • Damian Green 452 posts 1433 karma points
    Jun 04, 2014 @ 12:13
    Damian Green
    0

    Are you using v6 or 7?

    If so why dont you just get the IPublishedContent and then use the HasProperty and HasValue methods?

    var node = Umbraco.TypedContent(1076);
    
    if (node.HasProperty("prop"))  {}
    if (node.HasValue("prop")) {}
    

    I have typed that code from memory so hopefully it it right. :)

  • John Churchley 272 posts 1258 karma points c-trib
    Jun 04, 2014 @ 22:40
    John Churchley
    0

    Hi Damian I'm using version 7, thanks for the suggestion not sure that's what I'm looking for probably my explaination. Can this querying be used in a helper class or just a view? 

  • Damian Green 452 posts 1433 karma points
    Jun 05, 2014 @ 11:44
    Damian Green
    0

    Hi John

    If the class inherits from an umbraco class or has a the umbraco context - like a controller inherits from SurfaceController - that has the Umbraco helpers.

    This post might help explain it more: http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx

    I thought you were looking to test for the existence of a property and that it had a value.

    I don't know where from or how you are trying to access the properties but you can pass the Umbraco context into a class with say the current page using the IPublishedContent.

    Hope this helps and not confused you. :)

    Damian

Please Sign in or register to post replies

Write your reply to:

Draft