Copied to clipboard

Flag this post as spam?

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


  • Manasa 80 posts 201 karma points
    Mar 26, 2014 @ 08:32
    Manasa
    0

    Dynamically fetch default properties of a node

    Hi,

    How can i retrieve node's default properties like ID,Create Date,CreatorName etc dynamically?

    Thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 26, 2014 @ 08:43
    Jan Skovgaard
    0

    Hi Manasa

    What language do you want to use for doing it? It can be done with XSLT, Razor, C# and Umbraco:Items.

    Razor: Model.Id, Model.CreateDate, Model.Date, Model.CreatorName or @CurrentPage.Id, @CurrentPage.CreateDate, @CurrentPage.Date, @CurrentPage.CreatorName

    Xslt $currentPage/@id, $currentPage/@createDate, $currentPage/@date, $currentPage/@creatorName

    If you want to fetch the values directly on your templates then you can use UmbracoItems, which can be inserted using the context menu in the template.

    Don't know the C# syntax though but it should be possible to find in the documentation somewhere :)

    Hope this helps.

    /Jan

  • Manasa 80 posts 201 karma points
    Mar 26, 2014 @ 09:03
    Manasa
    0

    Hi Jan,

    I'm using C# to retrieve properties.

    Thanks

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 26, 2014 @ 09:19
    Dennis Aaen
    0

    Hi Manasa,

    Maybe this documentation about the NodeFactory can help you.

    http://our.umbraco.org/wiki/reference/api-cheatsheet/working-with-nodefactory

    /Dennis

  • Manasa 80 posts 201 karma points
    Mar 26, 2014 @ 09:19
    Manasa
    0

    Displaying default properties in checkboxlist

  • Manasa 80 posts 201 karma points
    Mar 26, 2014 @ 09:22
    Manasa
    0

    Hi Dennis,

    Is there any way where i need not hardcode the property names?

    Instead fetch them dynamically.

     

    Thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 26, 2014 @ 09:31
    Jan Skovgaard
    0

    Hi Manasa

    Could you ellaborate a bit about what you want to do by fetching the properties dynamically?

    Using the node factory you should be able to obtain the currentnode id and the use it to loop over any children, grandchildren etc. and fetch their ID's etc.

    /Jan

  • Bert 128 posts 251 karma points
    Mar 26, 2014 @ 09:38
    Bert
    0

    Do you want something like this?

    (Didn't test it)

    Node myNode                 =newNode(1234);
    string my
    CreatorName        = myNode.GetProperty("creatorName").Value;
    string myCreatorName        = myNode.GetProperty("createDate").Value;
    ...
  • Manasa 80 posts 201 karma points
    Mar 26, 2014 @ 10:21
    Manasa
    0

    Hi Bert,

    Is there a way to mention property names (creatorName,createDate) without hardcoding their names?

    Thanks

  • Bert 128 posts 251 karma points
    Mar 26, 2014 @ 10:52
    Bert
    100

    In version 4 you could do something like this:

    var document = new Document(1234); 
    foreach(var p in doc.getProperties){
    var value = p.Value;
    var alias = p.PropertyType.Alias;
    }

    But I think you will always need some  'hardcoding'. Is there a specific functionality you want to create? Maybe someone has a better solution for the specific problem?

  • Manasa 80 posts 201 karma points
    Mar 26, 2014 @ 11:13
    Manasa
    0

    Thanks Bert. :)

Please Sign in or register to post replies

Write your reply to:

Draft