Copied to clipboard

Flag this post as spam?

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


  • Damon 217 posts 287 karma points
    Aug 06, 2018 @ 15:31
    Damon
    0

    How do you check if a media item is being used on a page?

    Hi,

    does anyone know how to do this in code?

    thanks!

  • Ben Palmer 176 posts 842 karma points c-trib
    Aug 06, 2018 @ 20:31
    Ben Palmer
    0

    Hi Damon,

    I think we might need a bit more info for this one. Can you elaborate on what it is you're trying to do exactly?

    Thanks,

    Ben

  • Damon 217 posts 287 karma points
    Aug 07, 2018 @ 08:16
    Damon
    0

    Hi Ben,

    I want to iterate through the media section and check each media item to determine if it has been added to a page. E.g. has the media item added to the page using media picker,

    thanks,

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Aug 06, 2018 @ 21:21
    Dan Diplo
    0

    You could try a package like Nexu that can track usage: https://our.umbraco.com/projects/backoffice-extensions/nexu/

  • Louis Ferreira 69 posts 265 karma points
    Aug 07, 2018 @ 06:49
    Louis Ferreira
    0

    Hi Damon,

    The IPublishedContent object has extention methods for checking properties of the content.

    you could use:

    @Model.Content.HasProperty("yourPropertyAliasName")
    and 
    @Model.Content.HasValue("yourPropertyAliasName")
    

    So you could try doing

    @if(Model.Content.HasProperty("myAlias") && Model.Content.HasValue("myAlias")) {
        <h1>@Model.Content.GetPropertyValue<string>("myAlias")</h1>
        //or if using Models builder
        //Model.Content.myAlias
    }
    

    See this link for more details:

    https://our.umbraco.com/documentation/reference/querying/ipublishedcontent/Properties

    Hope this helps :)

    Louis

  • Damon 217 posts 287 karma points
    Aug 07, 2018 @ 08:18
    Damon
    0

    Hi Louis,

    dont think that is what is required.

    Want to iterate through the media folder and check if the media item is included on the page or not so will know wether or not the media item is being used.

  • Louis Ferreira 69 posts 265 karma points
    Aug 07, 2018 @ 08:42
    Louis Ferreira
    0

    Ok, I get it now...

    I don't think there is a way to programatically check that. But try this package...

    https://our.umbraco.com/projects/backoffice-extensions/nexu/

    The description says

    ..."This way a content editor can see where a page or media items is used..."

  • Damon 217 posts 287 karma points
    Aug 07, 2018 @ 08:46
    Damon
    0

    Hi Louis,

    do you know if this package will work straight away or does each page have to be saved to create the relation?

    thanks,

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Aug 07, 2018 @ 10:46
    Ismail Mayat
    0

    Damon

    In the nexu gui you can run something to re create all the link usages. Also it will setup events so that when item is saved it will then add the link.

    Regards

    Ismail

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Aug 07, 2018 @ 11:14
    Martin Griffiths
    0

    Hi Damon

    The package has two elements to it.

    1. Shows/warns of content usage when you try to delete it.
    2. A datatype that you add to your doctype/mediatype to show the usage.

    You can also set a couple of switches to prevent deletion or unpublishing of content if it is linked

Please Sign in or register to post replies

Write your reply to:

Draft