image is not displayed when working with alternates and medialibraryfield for blog post in orchard cms

174 views Asked by At

after trying different solution Now I had some information about my problem : I already 've added MediaLibraryPickerField for My BlogPost Type, I 'm using an alternate layout for my blog , with the name of Layout-url-test.cshtml that the name of my blog is test . and also creating Content-url-test.cshtml , Fields.MediaLibraryPicker.Summary-url-test.cshtml ,Parts.Blogs.BlogPost.List-url-test.cshtml , the layout is ok , and my blog posts with images is displaying media , but when I added alternate file Parts.Blogs.BlogPost.List-url-test.cshtml no images are displayed in blog post list and blog post detail ! I realized that there is some thing with my alternate files but I couldn't find any thing help full for my problem !!!

 var list = Model.ContentItems;
 var items = list.Items;
 var body = "";
 string name = string.Empty;
foreach(var post in items)
{

var blogPost = post.ContentItem;

 body = post.ContentItem.BodyPart.Text;

var field =(MediaLibraryPickerField) post.ContentField;
     name  =  field.DisplayName;

}

I could get text for bodypart but field always is null !!!

should I add some code lines in theme placement.info file ???

1

There are 1 answers

0
Shahin b On

If your try to add a MediaLibraryPickerField for your blog post there is no need to override other views like Fields.MediaLibraryPicker or etc. What you need is override:

Content-BlogPost.Detail.cshtml

Parts.Blogs.BlogPost.List.cshtml

but for listing all posts in BlogPost.List just loop through contents and pick the ImageField like this

 @foreach (var item in Model.ContentItems)
{

var mediaPart = ((Orchard.MediaLibrary.Fields.MediaLibraryPickerField)
item.ContentItem.BlogPost.[FieldName]).MediaParts.FirstOrDefault();

  ////////your mark up goes here 

<img src="@mediaPart.MediaUrl" alt="@mediaPart.Caption"/>
...
...

}

your placement:

 <Match ContentType="BlogPost">
    <!--<Match DisplayType="Summary">-->
     <Place Fields_MediaLibraryPicker="-"/>
     <Place Parts_Common_Body_Summary="Summary:0"
            Parts_Common_Body="Body:0"
            Parts_Tags_ShowTags="Tags:0"
            Parts_Common_Metadata_Summary="MetadataSummary:0"
            Parts_ListOfComments="Comment:0" 
            Parts_Comments_Count="CommentsCount:0" 
            Parts_CommentForm= "CommentForm:0"/>
    <!--</Match>-->


<!--<Match DisplayType="Detail">
      <Place Parts_Tags_ShowTags="Content:before.1"/>
      <Place Parts_Common_Metadata="Content:before.2"/>
      <Place Parts_Comments="Content:after.3"/>
    </Match>--> 


  </Match>

      </Match>