Custom Form Field "Grouping"

Topics: Customizing Orchard, Troubleshooting
Sep 21, 2013 at 6:56 PM
Hi All!

I have tried (and have actually had some success using the shape alternates for Content.Edit) In separating fields into "groups" So i can line them up properly using Twitter Bootstrap spans (example below):
@{
    dynamic content = Model.Content;
}

<div class="span6">
    @{
        foreach (var item in content)
        {
            if (item.Model.GetType().Name == "InputField")
            {
                if (item.Model.Name != "ContactTime")
                {  
        @Display(item);
                }
            }
        }
    }
</div>
<div class="span6">
    @{
        foreach (var item in content)
        {
            if (item.Model.GetType().Name != "InputField" || item.Model.Name == "ContactTime")
            {
        @Display(item);
            }
        }
    }
</div>
I guess my question is - is this the correct and/or easiest way to handle this, or is there a better way? (This was pulled from Orchard 1.6 and doesn't seem to work in 1.7 BTW)
Sep 21, 2013 at 7:23 PM
Edited Sep 21, 2013 at 7:23 PM
Updated question with a fully functional (1.7.1) version. Just curious if there is a better way to achieve this.
@{
    dynamic content = Model.Content;
}

<div class="span6">
    @{
        foreach (var item in content)
        {
            try {
            if (item.Model.Name != "Message")
            {
@Display(item);
        }} catch {}
}
    }
</div>
<div class="span6">
    @{
        foreach (var item in content)
        {
            try {
            if (item.Model.Field.Name == "Message")
            {
@Display(item);
        }} catch {}
}
    }
</div>