Copied to clipboard

Flag this post as spam?

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


  • Nathan 67 posts 146 karma points
    Oct 21, 2014 @ 08:13
    Nathan
    0

    Get only the first fieldset from property

    Hi,

    I'm using Archetype property editor and trying to grab only the first fieldset using foreach:

     foreach (var item in Umbraco.Content(5369).GetPropertyValue<Archetype.Models.ArchetypeModel>("myProperty"))
         {
           var icon = Umbraco.TypedMedia(item.GetValue("icon"));
           <img src="@icon.Url" />
           <span>@item.GetValue("iconTitle")</span>
         }
    

    How can I get only the first fieldset ?

    Dan

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 21, 2014 @ 08:19
    Dennis Aaen
    0

    Hi Dan,

    Maybe you could do something like this:

    foreach (var item in Umbraco.Content(5369).GetPropertyValue<Archetype.Models.ArchetypeModel>("myProperty").First())
         {
           var icon = Umbraco.TypedMedia(item.GetValue("icon"));
           <img src="@icon.Url" />
           <span>@item.GetValue("iconTitle")</span>
         }

    Hope this helps,

    /Dennis

  • Nathan 67 posts 146 karma points
    Oct 21, 2014 @ 08:30
    Nathan
    0

    I get an error 'ArchetypeModel' does not contain a definition for 'First'. Note there is one property with multiple fildesets (each fiedset has 2 fields).

    Thanks

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 21, 2014 @ 08:40
    Dennis Aaen
    0

    Hi Dan,

    Maybe this thread can be a help to solve your needs.

    http://our.umbraco.org/forum/developers/razor/54022-Checking-if-node-is-first-node-in-archetype

    /Dennis

  • Nathan 67 posts 146 karma points
    Oct 21, 2014 @ 09:26
    Nathan
    0

    Thanks Dennis, but this doesn't work for me, same error as before. Fieldsets are of type {Archetype.Models.ArchetypeFieldsetModel}

  • Danny Blatant 91 posts 358 karma points
    Oct 21, 2014 @ 18:23
    Danny Blatant
    0

    Hi Dan,

    I'm using an Archetype with multiple properties in each item, here's some code I just tested that works:

    @{
        ArchetypeModel test = Model.Content.GetPropertyValue<ArchetypeModel>("contentStack");
        foreach (var Slide in Model.Content.GetPropertyValue<ArchetypeModel>("contentStack")){
            if (Slide == test.First())
            {
                <pre>First Archetype Fieldset!</pre>
            }
            else
            {
                <pre>Not the first</pre>
            }
        }
    
    }
    

    Note I am using ArchetypeModel, not ArchetypFieldsetModel... Any reason why your using the ArchetypeFieldSetModel???

    For me, I debugged my example code and according to my debug the return from Archetype is a Archetype.Models.ArchetypeModel as per the below code

    var test = Model.Content.GetPropertyValue("contentStack");
    <pre>@test.GetType()</pre>
    

    I'm just working of the classic Archetype docs here : https://gist.github.com/kgiszewski/8863822

    Hope it helps!!!!

    Danny "Blatant"

Please Sign in or register to post replies

Write your reply to:

Draft