Copied to clipboard

Flag this post as spam?

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


  • Nicky 10 posts 89 karma points
    Sep 28, 2017 @ 14:08
    Nicky
    0

    Nesting Archetype with partial views

    Hi all,

    I'm new with Archetype and I can't figure out how to nest them. I want to build a "widget" based website where the client can add these "widgets" so he can build his own pages.

    This is what I did:

    1. I created a new data type called Slider, I chose Archetype as my property editor (obviously). I added one fieldset and in the properties section I added a text string

    2. I created a new data type called Page builder. In this data type I added multiple fieldsets (Header, Text and Slider).

    3. I created a new document type named Generic page where I added the Page builder

    In my GenericPage.cshtml I have the following code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Archetype.Extensions
    @using Archetype.Models
    
    @{
        Layout = "_Layout.cshtml";
    
        var fieldsets = Model.Content.GetPropertyValue<ArchetypeModel>("modules");
    }
    
    
    @Html.RenderArchetypePartials(fieldsets, "~/Views/Partials/Archetype/")
    

    The header and text renders perfectly but my slider isn't. How can I render the nested archetype data type?

    In my slider.cshtml I added the following code:

    <section class="slider">
        @foreach (var fieldset in Model.Content.GetPropertyValue<ArchetypeModel>("sliderItem"))
        {
            <h1>@fieldset.slideTitle</h1>
        }
    </section>
    

    I hope this make sence and you guys can help me out.

  • Tobias Klika 101 posts 570 karma points c-trib
    Oct 01, 2017 @ 21:10
    Tobias Klika
    0

    I have no clue how your model looks right now, but an easy solution to your problem is:

    1. Run site and attach debugger in VS
    2. Set a breakpoint in the line where the foreach is located (where you get the sliderItem)
    3. When the breakpoint is reached, inspect Model.Content.Properties.
    4. Find the sliderItem property and check the datatype or see if you've got an other error.
  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Oct 02, 2017 @ 02:59
    Nicholas Westby
    0

    FYI, this question was posted twice and was already answered here: https://our.umbraco.org/projects/backoffice-extensions/archetype/sound-off/88381-nesting-archetypes

Please Sign in or register to post replies

Write your reply to:

Draft