Copied to clipboard

Flag this post as spam?

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


  • David 29 posts 110 karma points
    Jan 19, 2015 @ 00:20
    David
    0

    Inherit property value from parent page & combining with current page

    Hi,

    I'm hoping to find the best solution for this requirement below.

    My node tree looks like this:

    Home
    - Sub1
    - Sub2
    - Sub3

    Home is Doctype "Home", Sub3 is Doctype "HomeSpecial".  HomeSpecial inherits from Home. Both Home and Sub3 have ArchetypeModel properties which I use to display a rotating banner, called "Features" (Defined on the "Home" doctype).

    When Sub3 is requested I want to show both Home's Features property contents and Sub3's Features property contents in the rotating banner.

    Thanks in advance.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 19, 2015 @ 09:45
    Lee Kelleher
    0

    Hi David,

    Did you want to combine the values in the editor itself (back-office)? or only on the front-end?

    If it's only on the front-end, how are you currently getting the values from your Archetype property? (via a controller or code in the view directly?)

    The general idea would be to get both ArchetypeModel objects and combine their fieldsets - then render them out.

    Cheers,
    - Lee

  • David 29 posts 110 karma points
    Jan 20, 2015 @ 00:48
    David
    0

    Hi Lee,

    Thanks for the response.

    I hadn't thought about combining the values  in the backend - but this would be a good option.  Is there a way you can suggest to achieve this?

    Alternatively, I can combine in the front-end.  I'm currently rendering the ArchetypeModel properties in a partial view:

    var model = Model.Content.GetPropertyValue<ArchetypeModel>("feature");

    Then looping through:


    @foreach (var fieldset in model)
                {
                    if (fieldset.HasValue("featureType"))
                    {
                   ...
                   ...
                    }
                {
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 20, 2015 @ 11:23
    Lee Kelleher
    100

    Hi David,

    Personally I'd go with handling this in the front-end (either controller or view). Do something like this:

    var parentFeature = Model.Content.Parent.GetPropertyValue<ArchetypeModel>("feature");
    var currentFeature = Model.Content.GetPropertyValue<ArchetypeModel>("feature");
    
    var combined = new List<ArchetypeFieldsetModel>();
    
    combined.AddRange(parentFeature.Fieldsets);
    combined.AddRange(currentFeature.Fieldsets);
    
    foreach (var item in combined)
    {
        ...
    }
    

    Basically you're making a new (empty) list of the fieldsets, then adding the parent fieldsets, then the ones from the current page.

    Hope this helps?

    Cheers,
    - Lee

  • David 29 posts 110 karma points
    Jan 29, 2015 @ 00:48
    David
    0

    Thanks for the help, Lee.  I'll give this approach a go.

    Cheers,

    David.

Please Sign in or register to post replies

Write your reply to:

Draft