Copied to clipboard

Flag this post as spam?

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


  • James Meredith 18 posts 91 karma points
    Apr 14, 2014 @ 12:12
    James Meredith
    0

    Getting crops from child pages in 7.1

    Hi 

    I'm trying to output the cropped image of child nodes in 7.11 but with no luck.  Here's what I have so far:-

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
        @* Pick the Home Banners Node  *@
        var bannerNode = Library.NodeById(1071);
    }
    
    @try{   
    <ul class="bxslider">
    @foreach (var childPage in bannerNode.Children.Where("Visible"))
    {
    
                <li>
                <div class="banner">
                    <img src="@childPage.GetCropUrl("bannerImage", "HomeBanner")" class="img-responsive" />
    
                </div>
                </li>
    }
    </ul>
    }catch(Exception ex)
    {
        <p>@ex.Message</p>
    }
    

    My cropper property alias is "bannerImage" and the crop alias is "HomeBanner"

    I have a feeling I'm missing something rather stupid but my img src keeps coming out blank.

    Thanks in advance

    James

  • Jeavon Leopold 3061 posts 13490 karma points MVP 9x admin c-trib
    Apr 14, 2014 @ 12:21
    Jeavon Leopold
    0

    Hi James,

    Your issue is that you are trying to use a Razor Macro which are only in Umbraco v7 for legacy support.

    Assuming you are using MVC templates, you should place your code directly into your View (template) or a Partial View instead of using a Macro. If you are using WebForms templates in v7, you will need Macros but they should be Partial View Macros.

    Hope that makes sense?

    Jeavon

  • James Meredith 18 posts 91 karma points
    Apr 14, 2014 @ 12:58
    James Meredith
    0

    Ah ok that does make sense. As I'm new to mcv I wonder how I get a node by id as Library.NodeById() only works in razor macros I assume?

    James

    Edit:

    Ignore this post I had mispelt a property all working fine now thanks 

  • Jeavon Leopold 3061 posts 13490 karma points MVP 9x admin c-trib
    Apr 14, 2014 @ 13:35
    Jeavon Leopold
    0

    Awesome, glad it's working!

    @Library.NodeById does not exist in MVC, you now use @Umbraco.Content

    Documentation for the UmbracoHelper can be found here

Please Sign in or register to post replies

Write your reply to:

Draft