Copied to clipboard

Flag this post as spam?

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


  • phil 16 posts 119 karma points
    Jan 07, 2019 @ 17:08
    phil
    0

    Reuse Partial on same template

    Hi, I'm looking for some help. I have currently created a template and have a partial loaded into it which gets some data from a set of child nodes. I'm wanting to use the same partial view again lower down but on the same page but have different child nodes which will mean the data show is different. The issue I have at the moment is I cant differentiate from the two partial. So the two partials are pulling in each others data. I want it so the first partial pulls in the first set of child nodes and the second one pulls in the second lot. How to i tell the item in the loop to only select the first batch ie partial 1? each partal is currently showing 8 child nodes where the first should just show 6 and the second should just show 2.

    <div class="row" style="margin-top: 70px;">
    
            @foreach (var item in currentPage)
            {
    
                @Html.Partial("~/Views/Partials/BlockSection.cshtml", item);
    
            }
    
        </div>
    
       some html
    
        <div class="row" style="margin-top: 70px;">
    
    
    
            @foreach (var item in currentPage)
            {
    
                @Html.Partial("~/Views/Partials/BlockSection.cshtml", item);
    
            }
    
        </div>
    

    enter image description here

  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Jan 07, 2019 @ 19:04
    Søren Kottal
    0

    Hi Phil

    How are you making the currentPage variable?

  • phil 16 posts 119 karma points
    Jan 07, 2019 @ 19:28
    phil
    0

    Hi,

    The below shows my currentPage.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{Layout = "Master.cshtml";`
    
    var currentPage = Model.Content.Children; }
    
  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Jan 07, 2019 @ 19:33
    Søren Kottal
    100

    Hi Phil

    You can divide them into two seperate variables like this:

    var firstSet = Model.Content.Children().FirstOrDefault();
    var secondSet = Model.Content.Children().Skip(1).FirstOrDefault();
    
    <div class="row" style="margin-top: 70px;">
    
            @if (firstSet != null)
            {
    
                @Html.Partial("~/Views/Partials/BlockSection.cshtml", firstSet);
    
            }
    
        </div>
    
       some html
    
        <div class="row" style="margin-top: 70px;">
    
    
    
            @if (secondSet != null)
            {
    
                @Html.Partial("~/Views/Partials/BlockSection.cshtml", secondSet);
    
            }
    
        </div>
    
  • phil 16 posts 119 karma points
    Jan 08, 2019 @ 08:19
    phil
    0

    That works just how I needed it too. Thank you

Please Sign in or register to post replies

Write your reply to:

Draft