Copied to clipboard

Flag this post as spam?

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


  • AvihayBit 149 posts 303 karma points
    Dec 29, 2014 @ 23:47
    AvihayBit
    0

    How do I get GetPropertyValue("Name") ??

    Hi,

    I want to get a node name,

    but for some reasons I need to get it like: @page.GetPropertyValue("Name")

    [page is DynamicPublishedContent]

    and not like: @page.Name

    Is it possible?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 30, 2014 @ 00:03
    Dennis Aaen
    0

    Hi AvihayBit,

    Since I don´t can see your full code snippet you could try this if your are in strongly typed context:

    @Model.Content.GetPropertyValue("Name")

    If you are in dynamic context should be able to do like this.

    @CurrentPage.Name 

    If one of the two example don´t help you, could you please then share your code that you have so far, Then it's much easier to help.

    Hope this helps,

    /Dennis

  • AvihayBit 149 posts 303 karma points
    Dec 30, 2014 @ 17:28
    AvihayBit
    0

    Hi Dennis,

    Thanks for you help :)

    As i wrote above- I cant use @CurrentPage.Name , although page is DynamicPublishedContent... And this is the reason:

    I created a GlobalHelper to add a postfix to every property alias, depending on the user's current language.

    I call the helper in the template this way:

    @page.GetPropertyValue(GlobalHelpers.PropertyPostfix("Name",System.Globalization.CultureInfo.CurrentCulture.Name, page))
    

    and this is the helper snippet:

    @functions {
        public static string PropertyPostfix(string propertyAlias,string langName, Umbraco.Web.Models.DynamicPublishedContent CurrentPage){
            var postFix = "";
            if(langName == "en"){postFix = "US";}
            if(langName == "fr"){postFix = "FR";}
            if((langName == "he")||(CurrentPage.GetPropertyValue(propertyAlias+postFix) == "")||(CurrentPage.GetPropertyValue(propertyAlias+postFix) == null)){ 
                return propertyAlias;
            }else{
                return propertyAlias+postFix;
            }
        }
    }
    

    It works perfectly, but I don't want to create another property that will be equivalent to Name, and when I Call the Name property that way, it returns empty... You have an idea?

  • Brian Williams 12 posts 33 karma points
    Dec 31, 2014 @ 13:27
    Brian Williams
    0

    Looking at Umbracos xml the attribute for name is called "nodeName" give that a shot. (note. this is for Umbraco 7 you can check yourself by either looking in the database or in the umbraco.config file, to check what the attribute is called for your version.)

  • AvihayBit 149 posts 303 karma points
    Dec 31, 2014 @ 21:42
    AvihayBit
    0

    I have tried that with no success already... returns an empty value...

  • AvihayBit 149 posts 303 karma points
    Jan 01, 2015 @ 23:24
    AvihayBit
    0

    Hey, there is any core member that can help here?!

    It sounds like it should be really simple, I just need to know what is the right syntax to get the default property values other than e.g. CurrentPage.Name / CurrentPage.Id ...

    Why CurrentPage.GetPropertyValue("Name") or CurrentPage.GetPropertyValue("Id") is empty?!?!

  • Brian Williams 12 posts 33 karma points
    Jan 02, 2015 @ 02:35
    Brian Williams
    0

    Did you look in the xml of your website to find the object you are trying to access and to check that those values are there? If they are not in there then you might just need to refresh your cache.

    Or, have you tried debugging it and looking at the available properties on the object?

    One other thing, dont you have to specify a type when using that method. i.e. GetPropertyValue

    p.s. If all you need to do is get the name you could always just use

    @Model.Content.Name

    There are a few options.

  • AvihayBit 149 posts 303 karma points
    Jan 02, 2015 @ 08:37
    AvihayBit
    0

    Hi Brian,

    Thanks for trying to help,

    Yes I took a look at the XML, and it seems that you can get only the properties that you created that way, but not the default. e.g:

    <TextPage id="2433" parentID="2432" level="2" creatorID="0" sortOrder="0" createDate="2014-05-06T00:07:36" updateDate="2014-12-23T18:32:51" nodeName="our facebook" urlName="our facebook" path="-1,2432,2433" isDoc="" nodeType="2426" creatorName="admin" writerName="admin" writerID="0" template="2431" nodeTypeAlias="TextPage">
          <umbracoNaviHide>0</umbracoNaviHide>
          <navName><![CDATA[our facebook]]></navName>
          <title><![CDATA[our facebook]]></title>
    ...
    

    I can get the 'title', 'navNam', and all other properties that I added, but not the default properties values that are above them (name, id, date...)

    GetProperty() doesnt helps either...

    If you read the earlier post you will see why I cant use @Model.Content.Name ....

  • Brian Williams 12 posts 33 karma points
    Jan 02, 2015 @ 15:39
    Brian Williams
    0

    I am in front of a computer now so I can maybe help a little better. Have you thought about rethinking your methodology?

    http://our.umbraco.org/documentation/Reference/Querying/DynamicNode/Properties

    The standard built in properties are just c# properties as opposed to "IProperty"s

    You could probably use reflection to do what you want ...

    http://stackoverflow.com/questions/5508050/how-to-get-a-property-value-based-on-the-name

    ... although I would recommend re-factoring.

  • AvihayBit 149 posts 303 karma points
    Jan 03, 2015 @ 21:17
    AvihayBit
    0

    Thanks Brian,

    I created a new helper for getting the Name instead of call the helper I wanted, Its not the best practice- but it works, so I didnt manage to check your reflection solution, but it makes sense...

    Thanks again!

  • Brian Williams 12 posts 33 karma points
    Jan 03, 2015 @ 23:24
    Brian Williams
    0

    No worries, I can't see any harm in writing a helper method to query the built in properties before looking in the custom properties. Seems perfectly reasonable to me. If if find anything helpful I will post back with it.

Please Sign in or register to post replies

Write your reply to:

Draft