Adding gallery to blog post not found

Jul 6, 2011 at 3:10 PM

Hi,
First, thanks for this great module.
I have added the gallery as part of a blog post, but when I display it on the blog view does not work.

I use the following code in Content-BlogPost..cshtml

-------------------------------------------------------------------------------------------------
@using Mello.ImageGallery.Helpers
@using System.Web.Mvc.Html
@{ Style.Require("ImageGallery"); }


@{
   
    var item = Model.ContentItem;
    var parts = (List<ContentPart>) item.Parts;    
   
    var imageGalleryPart = (Mello.ImageGallery.Models.ImageGalleryPart)parts.First(p => p.PartDefinition.Name == "ImageGalleryPart");
    var imageGallery = imageGalleryPart.ViewModel;
}

-------------------------------------------------------------------------------------------------

This code returns the object correctly in imageGalleryPart, but imageGallery return null


Thanks in advance

Coordinator
Jul 6, 2011 at 4:22 PM

Hello!

Thank you for your feedback.

Does your blog post content item have a related image gallery item? I tried to reproduce your issue but everything went fine here. Here are the steps I did:

  • Installed Orchard version 1.2.41
  • Installed ImageGallery version 1.2.2
  • Enabled ImageGallery module
  • Added an image gallery and some photos on it
  • Edited the blog post content type to add an Image Gallery part
  • Created a blog
  • Created a new blog post, selecting the image gallery that I created previously

And that’s it. Did you create an image gallery prior to creating the blog post? Maybe do you happen to have deleted the image gallery that a blog post was using? Try performing the steps that I outlined. Check you Orchard and Image Gallery versions. If you issue persists (or if it was resolved), please let me know.

Thanks!

Gabriel

Jul 6, 2011 at 5:21 PM
Hi, Gabriel.

Thanks for your fast answer. Yes, your right, my blog post should have a related image gallery.

I will try your instructions tomorrow, and i let know the results.

Thanks again!

Claudio
Jul 7, 2011 at 3:07 PM

Hi, Gabriel

The problem is my theme, and I did tests with "The Theme Machine" and it worked fine.

Surely this is because the "blog post template" to the default work well with the gallery.

But I must rewrite the template, so my question is should I add code to correctly view the gallery. I have tried using the code "ImageGallery.cshtml"

My code is as follows:

----------------------------------------------------------------------------------------

@using Orchard.Utility.Extensions;
@using Orchard.DisplayManagement.Shapes;
@using Orchard.ContentManagement;
@using Orchard.Core.Common.Fields;
@using Orchard.Tags.Models;

@* usings gallery *@
@using Mello.ImageGallery.Helpers
@using System.Web.Mvc.Html
@{ Style.Require("ImageGallery"); }


@{
  var contentTypeClassName =
    ((string)Model.ContentItem.ContentType).HtmlClassify();
   
    var homeUrl = Href("~/");
    var pathImages = Path.Combine(homeUrl,"Media/Default/");
   
    var item = Model.ContentItem;
    var parts = (List<ContentPart>) item.Parts;    
    var part = parts.First(p => p.PartDefinition.Name == "BlogPost");
    var volanta =  ((TextField)part.Fields.First(f => f.Name == "Volanta")).Value;
    var lnkImage = ((TextField)part.Fields.First(f => f.Name == "LinkImagen")).Value ?? "Posts/ImagenDefault.gif";
    var destacada = ((TextField)part.Fields.First(f => f.Name == "Destacada")).Value ?? "";

    var esDestacada = destacada != "";
   
    var imageGalleryPart = (Mello.ImageGallery.Models.ImageGalleryPart)parts.First(p => p.PartDefinition.Name == "ImageGalleryPart");
    var imageGallery = imageGalleryPart.ViewModel;

    var images = imageGallery != null ? imageGallery.Images : null;
}


@*<div class="content-item @contentTypeClassName postBusPrensa"> *@
<div class="divBodyBusPrensa" >
    <h1>
        <a href="@item.RoutePart.Path">@item.RoutePart.Title</a>
    </h1>
    <h2>
        @T(volanta)
    </h2>
    @T(item.BodyPart.Text)
</div>
<div class="divImagenBusPrensa" >
    <img src=@Path.Combine(pathImages,lnkImage) class="imagenPostBusPrensa"/>
</div>


@* @model Mello.ImageGallery.ViewModels.ImageGalleryViewModel *@

@if (imageGallery != null && imageGalleryPart.DisplayImageGallery)
{
    using (Script.Head())
    {
    <script type="text/javascript">  
        $(document).ready(function () {
            @Html.ImageGalleryScript("#slideshow", imageGallery.ImageGalleryPlugin)
        });
    </script>
    }
    <div id="slideshow">
        <ul>
            @foreach (var image in images)
            {
            <li>          
                @Html.ImageWithThumbnailSize(image)   
            </li>      
            }                    
        </ul>    
    </div>
}

----------------------------------------------------------------------------------------

Thanks!

Claudio