Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Mar 13, 2014 @ 17:21
    Steve
    0

    Pulling Images from a Node

    Hello,

    I am writing a Razor to pull all the images with the property "featuredImage" from within a nodes children, but I must not be calling them correctly, as the script won't load. What am I missing?

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        var i = 0;
        var newsRoot = Model.NodeById(5583); @* The ID of the starting node *@
        var alumniCategory = newsRoot.Children.Where("Visible"); @* The node containing the children with the "featuredImage" property *@
    <div class="slider"> @foreach (var item in alumniCategory ){ if ( item.Media("featuredImage").UmbracoFile != "" ){ <div class="slide" id="@i"> if ( item.isVideo != true) { <a href="@item.imageLink"><img src="@item.Media("featuredImage").UmbracoFile" /></a> } else { <a class="youtube" href="@item.videoURL?modestBranding=0&showinfo=0&autohide=1&autoplay=1&rel=0&fs=0&controls=0"> <img src="/media/1030033/VideoOverlay.png" class="overlay" /> <img src="@item.Media("featuredImage").UmbracoFile" /> </a> } <div class="caption">@item.copy</div> </div> i++; } } </div>
  • Dan Lister 416 posts 1974 karma points c-trib
    Mar 13, 2014 @ 17:36
    Dan Lister
    0

    I'm sure if its an issue but you seem to be using nested double quotes on two different lines. Try the following instead:

    <img src='@item.Media("featuredImage").UmbracoFile'/>
  • Dan Lister 416 posts 1974 karma points c-trib
    Mar 13, 2014 @ 17:44
    Dan Lister
    0

    Actually, ignore my last comment. I don't think its the cause of your problem. You seem to be missing some @ characters to signal the start of some Razor scripts. Try the following...

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        var i = 0;
        var newsRoot = Model.NodeById(5583);
        var alumniCategory = newsRoot.Children.Where("Visible");
    
        <div class="slider">
            @foreach (var item in alumniCategory)
            {
                if (item.Media("featuredImage").UmbracoFile != "")
                {
                    <div class="slide" id="@i">
                        @if (item.isVideo != true)
                        {
                            <a href="@item.imageLink"><img src='@item.Media("featuredImage").UmbracoFile' /></a>
                        }
                        else
                        {
                            <a class="youtube" href="@item.videoURL?modestBranding=0&showinfo=0&autohide=1&autoplay=1&rel=0&fs=0&controls=0">
                                <img src="/media/1030033/VideoOverlay.png" class="overlay" />
                                <img src='@item.Media("featuredImage").UmbracoFile' />
                            </a>
                        }
                        <div class="caption">@item.copy</div>
                    </div>
                    i++;
                }
            }
        </div>
    }
  • Steve 472 posts 1216 karma points
    Mar 14, 2014 @ 13:17
    Steve
    100

    Actually Dan, It was the syntax for pulling the Media items.

    I was using src="'@item.Media("featuredImage").UmbracoFile' and needed to use src="@item.Media("featuredImage", "umbracoFile")".

    Thanks for your suggestions though. 

Please Sign in or register to post replies

Write your reply to:

Draft