This project is read-only.

Creating different handlings of MediaPicker field

Topics: Customizing Orchard
Apr 27, 2012 at 1:24 AM

Hi, I'm a newbie so sorry if this is a silly question.

I have created a Content Type, "Executive Team Member" which contains a Title, Body, is containable and Media Picker (Photo) field.  I then created a list of these content types.

What I can seem to figure out is how to display the Media Picker field differently depending upon if it is displayed in a Summary or Detail.  For example, on the list page where it will list each Executive Team Member, I want to display the photo field small and on the left, while on the Detail page display it big and on the right.  

I've tried using an alternate for the field but couldn't figure it out how to make it distinguish from the being in a Summary vs. Detail DisplayType. I tried using the Model to access the parent's Displaytype.  

I need the end result is simply change a class

<div class="et-photo"><img src="@Href(Model.ContentField.Url)" /></div>


<div class="et-summary-photo"><img src="@Href(Model.ContentField.Url)" /></div>

So can I access the parent's DisplayType from within a field?  Is there another way to do this?

Thanks in advance.

Apr 27, 2012 at 1:40 AM

The display type is not a property of the parent, it's a property of the shape. If you do Model.Metadata.DisplayType, that should do the trick. But alternates really are the correct way of dealing with that.

Apr 27, 2012 at 2:35 AM

Thanks a ton, that worked!  Thanks for the super fast reply too!  

One other question.  I'm having a problem grasping some simple things like how to access certain properties / fields / data / etc. 

For example, the Recent Blog posts alternate that displays just a list of links that are titles.... as below.  I've used the Designer tools and shape tracing to try to figure out the Model but pretty much get lost.  

For a simple example, how would I access the published date? My assumption would be something like post.CommonPart.PublishedUtc.  Sorry, I'm getting lost with tracking the models.

@using Orchard.ContentManagement;
    IEnumerable<object> blogPosts =
@if (blogPosts == null || blogPosts.Count() < 1) {
    <p>@T("No posts.")</p>
else {
    <ul class="content-items">
    @foreach (dynamic post in blogPosts) {
        string title = post.Title;
        ContentItem item = post.ContentItem;
        <li class="content-item-summary">
            @Html.ItemDisplayLink(title, item)

Apr 27, 2012 at 5:03 AM

That sounds about right. What happens when you try?

Apr 28, 2012 at 1:12 AM

That would just display nothing.  But I did figure it out to be post.ContentItem.CommonPart.PublishedUtc.