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
    Aug 23, 2013 @ 16:57
    Steve
    0

    Load images from a node

    I've been away from coding Razor and have forgotton a few things like how to refrence all the images within a folder. The images are stored in a node with doctype "CareerServicesPartnerFolder" and all the images are uploaded via the media picker and have the doctype "CareerServicesPartner".  I have what I thought would work, if someone could look it over and help me out, that would be great!

    @inherits umbraco.MacroEngines.DynamicNodeContext
        @{
            var root = Model.AncestorsOrSelf("CareerServicesHome");
            foreach(var partner in root.Decendants("CareerServicesPartnerFolder")) {
                <div class="imageSlide">
                    <a class="partner-box" target="_blank" href="@partner.Url" title="@partner.Name" >
                      <img src="partner.MediaById(Model.photo).umbracoFile" title="@partner.Name" alt="@partner.Name" /> />
    
          </a>
    
           </div>
                    };
        }
  • Steve 472 posts 1216 karma points
    Aug 23, 2013 @ 19:15
    Steve
    0

    I've got it to load the @partner.Name, but not the images using this:

    @{
            var root = Model.AncestorOrSelf("CareerServicesHome");
    
            foreach(var partner in root.Descendants("CareerServicesPartner")) {
                <div class="imageSlide">
                    <a class="partner-box" target="_blank" href="@partner.partnerUrl" title="@partner.linkTitle" >
    
                      <img src="Model.MediaById(@Model.logo).umbracoFile" title="@partner.linkTitle" alt="@partner.Name" />
    
          </a>
    
           </div>
                    };
        }
  • Moran 285 posts 934 karma points
    Aug 26, 2013 @ 15:56
    Moran
    0

    I use this solution: I get the media Id and create a DynamicMedia object.

    @helper RenderSlideImage(DynamicNode page)
    {
        string imageId = recommendPage.GetPropertyValue("recommendImage");
    
        if (!string.IsNullOrEmpty(imageId))
        {
            DynamicMedia recommendImage = new DynamicMedia(imageId);
            <img src="@recommendImage.NiceUrl" alt="@recommendImage.Name" class="add-border alignright imgProtfolioRe"/>
        }
        else
        {
            <img src="../images/avatar.png" alt="avatar" class="add-border alignright imgProtfolioRe"/>
        }
    }
    
  • Steve 472 posts 1216 karma points
    Aug 26, 2013 @ 16:07
    Steve
    100

    Thanks Moran. I ended up making it harder than it needed to be. All I had to do was use this code (notice the image. "logo" is an alias attached to the images):

    <div id="slider">
        <ul class="bxslider">
    
        @{ 
            var root = Model.AncestorOrSelf("CareerServicesHome");
    
            foreach(var partner in root.Descendants("CareerServicesPartner")) {
    
    
                    <li><a class="partner-box" target="_blank" href="@partner.partnerURL" title="@partner.linkTitle" >
           @* for source of images using an uploader only need to use @yourCurrentNode.parameterAlias  *@
                      <img src="@partner.logo" width="180px" title="@partner.linkTitle" alt="@partner.Name" />
    
          </a></li>
    
    
    
                    };
    
        }
                    </ul>
                        </div>
Please Sign in or register to post replies

Write your reply to:

Draft