Copied to clipboard

Flag this post as spam?

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


  • James 251 posts 1169 karma points
    Dec 09, 2014 @ 15:14
    James
    0

    Accessing properties

    Hi Guys,

     

    I'm hoping this is as easy as the title suggests :)

    I currently have a page (event) that has a multi-node picker called "associated". it allows users to select content from the site that is associated with an event.

    For each event I want to be able to show all the associated content on a sidebar.

    I want to be abel to display : Name/ URL/ Image

    I can get name and URL quite easily but i'm finding it hard to access any of the other properties for the associated content.

    Heres my code:

     

    @using umbraco.MacroEngines;

    @using Fact.Classes;

    @using Umbraco.Core.Models;

    @inherits umbraco.MacroEngines.DynamicNodeContext

    Array associatedIds = Model.associated.ToArray();

    foreach (DynamicNode n in associatedIds)

        {

     

            <div class="large-12 columns">

                <div class="large-4 columns">

                    <a href="@n.Url">

                     <img src="@n.backgroundImage" alt="@n.Name" />

                    </a>

                </div>

                <div class="large-8 columns">

                    <a href="@n.Url">

                        <h4>@n.Name</h4>

                    </a>

     

                </div>

     

            </div>

     

        }

    The alias of the property I am trying to select is : backgroundImage. But i cant select it. And when i do put it in i get an error:

    Is there any way to access the media of an associated content item?

     

     

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 09, 2014 @ 15:23
    Dennis Aaen
    0

    Hi James,

    What if you do something like this would this work.

    var selectedMedia = n.Media("backgroundImage");
    <img src="@selectedMedia.umbracoFile" alt="@selectedMedia.Name"/>

    Hope this helps,

    /Dennis

  • James 251 posts 1169 karma points
    Dec 09, 2014 @ 15:25
    James
    0

    Hi Dennis,

     

    Thanks for the response. This doesnt seemed to have worked :(

     

    It's a tricky one.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 09, 2014 @ 15:28
    Dennis Aaen
    100

    Hi James,

    Okay what if you do:

    <img src="@n.backgroundImage.Url" alt="@n.Name" />

    Hope this helps,

    /Dennis

  • James 251 posts 1169 karma points
    Dec 09, 2014 @ 15:32
    James
    0

    Still nothing. I'm trying a few different things. Thanks for your input so far.

     

    Everything else loads [email protected]  +  @n.Url

  • James 251 posts 1169 karma points
    Dec 10, 2014 @ 12:24
    James
    0

    Thanks for the help. Problem is solved.

     

    var imageUrl = fm.GetImageFromMedia(n, "backgroundImage");

    @imageUrl.ImageURL

     

    This worked.

     

    Thanks for your help and response.

Please Sign in or register to post replies

Write your reply to:

Draft