0
votes

For many of Custom Types created, we have a Query for them. These queries are being used by Projection Widgets (Within Zones).

Few of the custom types have Media Picker field.The Layout type I used for my Queries is the Shape type as seen below:

=>>> Queries: enter image description here

=>>> Layout: enter image description here . I have followed the steps from here.. I specified the name of the shape as : UpcomingHighlightsImages as seen below:

enter image description here

and then included the view: UpcomingHighlightsImages.cshtml in my Themes/MyFirstTheme/Views folder.

Everything works fine upto here.

In the View, problem is that there is NO way to read the Image Metadata such as altText, altHeight etc... Neither there seems to be a way to set these metadata firstly in Orchard itself.

@using Orchard.ContentManagement
@using Orchard.Core.Title.Models
@using Orchard.Fields.Fields
@using Orchard.Taxonomies.Fields
@using Orchard.Core.Common.Fields;
@using Orchard.MediaLibrary.Fields;

@{
    var HighlightItems = ((IEnumerable<ContentItem>)Model.ContentItems).ToList(); 
}

@foreach (var item in HighlightItems) 
    {
        String LinkUrl = ((TextField)item.Parts.SelectMany(x => x.Fields).Single(x => x.Name == "LinkURL")).Value;
        String ImagePath = ((MediaLibraryPickerField)item.Parts.SelectMany(x => x.Fields).Single(x => x.Name == "MainImage")).MediaParts.First().MediaUrl;
        <div>
            <a target="_blank" href="@LinkUrl">
                <img src="@ImagePath"  />
            </a>
        </div>
    }

So, as seen in above code and the tag, I need:

  • Set the altText, altHeight property of Image in ORchard CMS
  • Read these in my view , the way I read LinkUrl and ImagePath

Please guide me !

1

1 Answers

0
votes

See how you got the first media part in that ImagePath expression? Well, then you can take that part and get Title, Caption, AlternateText, etc. from it. You can also As<ImagePart>() it and get its Width and Height.