Copied to clipboard

Flag this post as spam?

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


  • karen 186 posts 461 karma points
    May 15, 2014 @ 17:12
    karen
    0

    need to get first node from Multi-Node Tree Picker

    I am trying to do this new site in MVC instead of webforms and xslt so I can learn MVC and razor, but things that are so simple to do in xslt seem so difficult with razor. Please help me out, I am sure this is a simple question.

    I am using Umbraco v6.1.6 

    I have a Multi-Node Tree Picker on my page (alias= 'pageContent'), and I want to get the first item.

    In xslt that would be something simple like:

    <xsl:variable name="myNode" select="$currentPage/pageContent/MultiNodePicker/nodeId[1]"/>

     

    I am looking at this page as reference, but not sure how to get it to work:  http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/get-values-from-ucomponents-multi-node-tree-picker-multiple-textstring

    I tried the first example there and the xpath example, but they both  throw an error.

    Here is my master template, just right now simply trying to print out the node id to start.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = null;
    }
    @Model.XPath("pageContent/MultiNodePicker/nodeId[1]")

    but the error I get is:

     'Umbraco.Web.Models.RenderModel' does not contain a definition for 'XPath

     Am I just missing something to use the dynamic node stuff?  I can't find anywhere that says what I need to include to use that.  (Also tried using @CurrentPage instead of @Model but @CurrentPage doesn't exist)

    Next step would be to get the actual node represented by that Id so I can use it to display property values of.  So if you have a full solution that would be great... :)

     

  • karen 186 posts 461 karma points
    May 15, 2014 @ 19:25
    karen
    0

    ok, 3 hours later finally got something to work: 

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
    Layout = null;
    int[] nodeList = uQuery.GetXmlIds(CurrentPage.pageContent.ToXml());
    @nodeList[0];
    }

    now to try to get the node and use that... ( I am not sure why anyone things MVC is easier.... ?? uQuery.GetXmlIds makes no intuitive sense! )

    Also I guess I was trying @CurrentPage in stead of just CurrentPage before ...

  • karen 186 posts 461 karma points
    May 15, 2014 @ 22:16
    karen
    0

    And lastly, got the node part etc:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = null;
        int[] nodeList = uQuery.GetXmlIds(CurrentPage.pageContent.ToXml()); 
        dynamic pageContent = null; 
        if (nodeList.Count() > 0) { pageContent = Umbraco.Content(@nodeList[0]); }
    }

    and then to use it later in the page:

    @if ( pageContent!= null && pageContent.HasValue("metaTitle")) { 
    @pageContent.metaTitle; 
    };
Please Sign in or register to post replies

Write your reply to:

Draft