Copied to clipboard

Flag this post as spam?

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


  • egeek 40 posts 179 karma points
    Nov 17, 2013 @ 02:24
    egeek
    0

    MNTP GetPropertyValue

     

    I have made a folder (node) containing nodes of brands. Each brand doc type have a brandName property (text string).
    I have extended my product doc type with a MNTP called "brandPicker".

    On my product view (view.cshtml) I want to get the "brandName" from the selected node in my MNTP.
    Second, if the "brandName" is null, I want to retreive the node name instead.

    I can only get the nodeId from the selected node by returning: string brand = TC.GetPropertyValue(storeId, mainProduct, "brandPicker");

    Can anyone please help me?

     

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Nov 17, 2013 @ 13:07
    Ali Sheikh Taheri
    0

    Hi Eqeek,

    Welcome to Umbraco Forum.

    If you are using version 6 then you could do this:

    if (TC.HasProperty("brandPicker") && TC.HasValue("brandPicker"))
    {
        @Umbraco.TypedContent(TC.GetPropertyValue<string>("brandPicker")).Name
    }
    else
    {
        @TC.Name
    }
    

    Cheers

    Ali

  • egeek 40 posts 179 karma points
    Nov 17, 2013 @ 15:30
    egeek
    0

    Hi Ali,
    Thanks for your answer.

    I installed Tea Commerce starterkit and even upgraded Umbraco manually to 6.1.6, but the namespace TC doesn't contain the properties "HasProperty" and "HasValue". Furthermore the namespace "Umbraco" can't find "TypedContent". 

    The only property properties I can grab from TC is "AddOrUpdateOrderProperty", "GetPropertyValue" and "GetXmlPropertyValue". 

  • egeek 40 posts 179 karma points
    Nov 18, 2013 @ 03:37
    egeek
    100

    I finally solved it.

    First I check if the current node contains a property called "brandPicker" and if the property has a value. If so, I get the value (id of the node) and create a new DynamicNode with it.

    [code]DynamicNode currentPage = Model;
    int brandPickerId = 0;
    if (currentPage.HasProperty("brandPicker") && currentPage.HasValue("brandPicker"))
    {
         brandPickerId = int.Parse(currentPage.GetPropertyValue("brandPicker"));
    }
    var brand = new DynamicNode(brandPickerId);
    [/code]

    Second I check if the DynamicNode returned an Id and if has a propertyValue "brandName" If so, I get the PropertyValue "brandName" from that node. If not, I simply return the name of the node.

    [code]@if (brand.Id != 0 && brand.HasValue("brandName"))
    {
         @brand.GetPropertyValue("brandName")
    }
    else
    {
         @brand.Name
    }
    [/code]

Please Sign in or register to post replies

Write your reply to:

Draft