Copied to clipboard

Flag this post as spam?

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


  • Brian McNally 17 posts 105 karma points
    Feb 27, 2014 @ 17:13
    Brian McNally
    0

    Partial Macro View File Syntax

    I'm trying to setup my first partial view macro file and running into a syntax problem I think. Or perhaps I'm going about this all wrong, either way a little guidance would be MUCH appreciated.

    I am on v6.1.6 and am trying to pull in a list of documents that have been selected to be on the current page. I hope this makes sense. In other words, the document type for document asset has a multi-node tree node picker that saves the results in csv. I would like to then place those documents on the correct page as appropriate.

    I have the following hard coded which does the trick, but I can't seem to figure out how to use the @CurrentPage.ID variable in place of the hardcoded \"2524\".

    Thanks

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    
    @if (Model.MacroParameters["nodeID"] != null)
    {
        @* Get the start node as a dynamic node *@
        var startNode = Umbraco.Content(Model.MacroParameters["nodeID"]);
        var curPage = CurrentPage.Id.ToString();
        var docs = startNode.Children.Where("Visible && assetPlacement.Contains(\"2524\")");
        if (startNode.Children.Where("Visible").Any())
        {
            <ul>
                @foreach (var page in docs)
    
    
    
                { 
                    <li><a href="#">@page.documentTitle</a>@curPage (@CurrentPage.Id) @page.assetPlacement</li>
                }
            </ul>
        }    
    }
    
  • Damian Green 452 posts 1433 karma points
    Feb 27, 2014 @ 17:28
    Damian Green
    0

    I normally have a field on the data type which is a MNTP.

    Get the value of that field and split it into an array then get all the content nodes and iterate over them.

    string nodesCSV = Model.Content.GetPropertyValue<string>("mntpProperty");
    nodesCSV = string.IsNullOrEmpty(nodesCSV) ? string.Empty : nodesCSV;
    
    var relatedDocs = nodesCSV.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse); 

    Then with the array:

    @foreach (var id in relateDocs) {
           IPublishedContent relatedDoc = Umbraco.TypedContent(id);
        //Do your stuff with this node
    }

    e.g.

    <li><a href="#">@relatedDoc.GetPropertyValue<string>("documentTitle")</a>

    Does that help at all?


Please Sign in or register to post replies

Write your reply to:

Draft