Copied to clipboard

Flag this post as spam?

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


  • John 3 posts 83 karma points
    Dec 17, 2021 @ 11:52
    John
    0

    Multiple Instances of Composition / Partial

    Hi,

    I am relatively new to Umbraco (and coming back to .NET after many, many years away), but have ended up on a project using it (v8). I am finding it fascinating at the moment. The site I am building has a lot of different layouts / templates (each page seems to be different), so I am building up each page using partials and compositions where possible, and nested content in other areas.

    I have tried the grid with Macros and I didn't get on with it for my circumstances.

    The problem I have is that some of the pages have 2, or more, instances of the same partial, seperated by another partial. e.g. layout could be something like:

    • Hero
    • Banner with some text
    • Block of content
    • Banner with some text (number 2)
    • Block of content (number 2)

    I can add them to the document type, but when I try to render them using Html.Partial I get the same content in each (the first instance content).

    Does anyone have an advice on how I can overcome this and use multiple instances of the same partial on the page? Can I pass an ID to the partial so it identifies the correct version? I have searched the docs and couldn't find any indication on it as yet.

    Thanks in advance,

    John

  • Ambert van Unen 175 posts 817 karma points c-trib
    Dec 20, 2021 @ 13:07
    Ambert van Unen
    100

    Hi John,

    You can simply pass the Model (or specific data) to a partial that you are rendering, for example:

     @Html.Partial("~/Views/Partials/RenderComponents.cshtml", Model)
    

    If you're using Umbraco8.7+ I'd recommend using the BlockList Editor, so you can easily add new components to a page. I think it's exactly what you are looking for: https://our.umbraco.com/Documentation/Fundamentals/Backoffice/property-editors/built-in-property-editors/Block-List-Editor/

  • John 3 posts 83 karma points
    Dec 20, 2021 @ 18:15
    John
    0

    Thanks for the response. I will take a look at the block list editor, sounds like the sort of thing I need.

    Update - This is exactly what I needed. Thanks to Ambert for the help.

Please Sign in or register to post replies

Write your reply to:

Draft