Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul Wright 16 posts 97 karma points
    Oct 29, 2019 @ 15:48
    Paul Wright
    0

    Displaying Media Folder within a page

    Sorry if this is a novice question but i have looked across this forum and unable to locate a solution for my issue.

    One of our website have requested to be able to simple upload a number of items into a selected folder in the media section of Umbraco and this folder to be displayed on a page is a list format (links to the items aswell).

    the folder is set two levels down in the media folder

    My question is how to gather the items from this folder and display them in the best method?

    once again sorry if this is a dumb question. this is the first time I've ever attempt to gather information from a media folder so i would be grateful for the support

    Folder structure ?

  • Jeffrey Veer 41 posts 308 karma points
    Oct 29, 2019 @ 16:11
    Jeffrey Veer
    0

    Hi Paul,

    Do you want to link the Media folder to a certain page or do you want to retrieve a Media folder from any Template/View?

    If you want to link a Media folder, you can modify the Document Type and use a Media Picker as the property editor. This way you can retrieve the Media folder from the Template/View in the same way you retrieve normal properties: Model.Value<IPublishedContent>("mediaFolder"). This will then allow you to retrieve all Children or Descendants using the functions .Children() or .Descendants().

    If you are using ModelsBuilder the media items can be retrieved in a similar way using Model.MediaFolder.Children().

    If you want to retrieve a specific Media folder on any Templates/Views, you can use the MediaService, more information on Our Umbraco: https://our.umbraco.com/documentation/reference/management/services/mediaservice/.

    Note: You might want to include some null-checks to make sure the page doesn't break.

    If you have any further questions, let me know and I will try to help.

  • Paul Wright 16 posts 97 karma points
    Oct 30, 2019 @ 15:37
    Paul Wright
    0

    Hi Jeffery,

    If you want to link a Media folder, you can modify the Document Type and use a Media Picker as the property editor. This way you can retrieve the Media folder from the Template/View in the same way you retrieve normal properties: Model.Value

    I Think this is the what i am attempt to do, I basically want to display every child item within the Minute folder in a list. i will go away and try and use this information.

    This is a complete guess but am i looking for something like this below:

    var media = Model.Value<IPublishedContent>("Minutes");
    var meetingItems = Media.Children();
    
    @foreach (var item in MeetingItems) 
    {
        here I do stuff..
    }
    

    the Items are not Images, they are PDF btw

  • Jeffrey Veer 41 posts 308 karma points
    Oct 30, 2019 @ 15:49
    Jeffrey Veer
    0

    Hi Paul,

    The code you provided should work, are you sure you set the Media Picker property editor to allow only a single item to be selected?

    If this isn't the case, you might want to try retrieving the data as an IEnumerable instead:

    Model.Value<IEnumerable<IPublishedContent>>("minutes");
    

    I tried retrieving a Media folder by id and displaying it's children, which worked as expected:

    @foreach (var media in Umbraco.Media(1107).Children)
    {
        <img src="@media.GetCropUrl(200, 200)" />
    }
    

    Let me know if this may fix your issue

  • Paul Wright 16 posts 97 karma points
    Oct 30, 2019 @ 16:00
    Paul Wright
    0

    Would this work with PDF Format? i just want to display the name of the document and also the link to the item.

    thanks

  • Jeffrey Veer 41 posts 308 karma points
    Oct 30, 2019 @ 16:03
    Jeffrey Veer
    100

    Yes, should work as it's just a File type:

    @foreach (var media in Umbraco.Media(1107).Children)
    {
        <a href="@media.Url">@media.Name</a>
    }
    
  • Paul Wright 16 posts 97 karma points
    Oct 31, 2019 @ 13:56
    Paul Wright
    1

    Jeffrey for you help on the matter, manage to get it all up and running without any major issues.

    thanks again

Please Sign in or register to post replies

Write your reply to:

Draft