Copied to clipboard

Flag this post as spam?

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


  • Sjoerd Stottelaar 31 posts 189 karma points
    Nov 11, 2021 @ 12:49
    Sjoerd Stottelaar
    0

    Nested Content template alias with MediaPicker3 and files

    I want to show the name of a media file (PDF) within a Nested Content template alias field. I want to use it with the MediaPickerV3, so not the legacy version. When I put the alias ({{file}}) of the property in the template field, I get this:

    [{"key":"b273a130-0f99-4eb1-94fc-650e4f489ff3","mediaKey":"a96e7ab3-407a-4b42-9bbb-c098d51b1e09","crops":[],"focalPoint":{"left":0.5,"top":0.5}}]
    

    There doesn't seem to be a name field present. In my Razor templates I would dig deeper with the .MediaItem property, but that doesn't seem to do anything in the template field. The documentation on this topic doesn't say anything about a media file.

    Does anyone know if it's possible to show the name of the media item? Would love to know how!

  • Daisy White 5 posts 76 karma points
    Feb 23, 2024 @ 19:51
    Daisy White
    0

    I am trying to do the exact same thing! Did you figure it out?

    We upgraded to Umbraco 10, but I think its mostly the same in this case.

    Our nested content also had a custom Image picker, and we wanted to show the filename for. Because it uses a custom property editor that we wrote, I was able to modify that code to display the filename. I did this by adding the filename to the newMediaEntry (in JavaScript), before sending that object to the backend to save.

    But for a built in property editor I fear it is impossible. Because you can't access the JavaScript code to add that property. When you save media, Umbraco adds it to the table: umbracoPropertyData (cmsPropertyData for v8 I think). What is saves to that table is this thing: "[{"key":"b273a130-0f99-4eb1-94fc-650e4f489ff3","mediaKey":"a96e7ab3-407a-4b42-9bbb-c098d51b1e09","crops":[],"focalPoint":{"left":0.5,"top":0.5}}]"

    Like I said, I was easily able to add the filename to that thing^ by adding it to the javascript that saved it. But you can't modify the javascript for an umbraco property ediotr....

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 25, 2024 @ 07:46
    Chriztian Steinmeier
    1

    Hi Sjoerd,

    I don't know if it works in Nested Content, but it does work for BlockGrid and BlockList items:

    {{(file[0].mediaKey | mediaItemResolver).name}}

    or this alternative for older versions:

    {{ "umb://media/" + file[0].mediaKey | ncNodeName }}

    I got these from Joe Glombek's cheatsheet here: https://joe.gl/ombek/blog/umbraco-angularjs-filter-cheat-sheet

    Hope this helps!

    /Chriztian

  • Daisy White 5 posts 76 karma points
    Feb 26, 2024 @ 16:56
    Daisy White
    1

    Chriztian, thank you for the input. It worked for me in nested content!!!

    However, I had to change it a little bit:

    {{(file[0].mediaKey | mediaItemResolver).name}}
    

    changed to

    {{(galleryImageSlideImage[0].mediaKey | mediaItemResolver).name}}
    

    where "galleryImageSlideImage" is the alias of the image property on my document type.

Please Sign in or register to post replies

Write your reply to:

Draft