Copied to clipboard

Flag this post as spam?

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


  • Aximili 177 posts 278 karma points
    Sep 03, 2014 @ 09:31
    Aximili
    0

    How to get child nodes in layout (.cshtml)?

    This is what I am doing

    Below is the code circled red (where the error is):

    @foreach (var slide in Model.Children)

    I think you used to be able to do something like that in Umbraco 4.7 (or I may have missed something)

    Anyway, how do you loop through the child nodes correctly?

    Thanks in advance

  • Alex Skrypnyk 6054 posts 23213 karma points MVP 5x admin c-trib
    Sep 03, 2014 @ 10:27
    Alex Skrypnyk
    2

    Hi Hardi,

    Try to use 'Model.Content.Children'.

    Thanks, Alex

  • Dennis Aaen 4491 posts 18156 karma points admin hq c-trib
    Sep 03, 2014 @ 11:08
    Dennis Aaen
    101

    Hi Hardi,

    In addition to Alex post I would like to add.

    In Umbraco 7 you have two different options. You can use dynamic razor, by using the @CurrentPage, so in dynamic it will looks like.

    @foreach (var slide in CurrentPage.Children){

    }

    And you can use the strongly typed razor as Alex shows in his post

    @foreach (var slide in Model.Content.Children){

    }

    The documentation can you find here http://our.umbraco.org/documentation/Reference/Templating/Mvc/views and http://our.umbraco.org/documentation/reference/templating/mvc/partial-views

    Here a some documentation about how to converting a PartialView Macro from a legacy RazorMacro Script http://our.umbraco.org/documentation/reference/templating/Macros/Partial-View-Macros/#ConvertingaPartialViewMacrofromalegacyRazorMacroScript

    Hope this helps,

    /Dennis

  • Alex Skrypnyk 6054 posts 23213 karma points MVP 5x admin c-trib
    Sep 03, 2014 @ 11:12
    Alex Skrypnyk
    0

    Also you can use uSiteBuilder for creating strongly typed models and then using it in views. ))

    /Alex

  • Aximili 177 posts 278 karma points
    Sep 04, 2014 @ 02:14
    Aximili
    0

    Perfect! Thanks a lot Alex and Dennis!

    Now, do you guys know if the following code can be shortened?

    @foreach (var slide in CurrentPage.HomeSlides)
    {
        string link = slide.link;
        if(string.IsNullOrEmpty(link)) {
            <img src="@slide.image" alt="@slide.Name" />else { 
            <a href='@slide.link' target='@Web.TargetOfLink(slide.link)'><img src="@slide.image" alt="@slide.Name" /></a>
        }
    }
    
  • Aximili 177 posts 278 karma points
    Sep 04, 2014 @ 02:27
    Aximili
    0

    Hi Alex, I just had a look at uSiteBuilder and I wonder if it is for U7, because it is still mentioning master pages and user controls. They're not for MVC, are they?

    EDIT: I just noticed there is a newer version but couldn't find the website for it. It looks very interesting, do you know if it takes time to learn? And is there any tutorial for the new version? Thanks again!

  • Alex Skrypnyk 6054 posts 23213 karma points MVP 5x admin c-trib
    Sep 04, 2014 @ 08:26
    Alex Skrypnyk
    1

    Hi Hardi,

    Look at : http://www.vegaitsourcing.rs/#!/articles/2014/03/usitebuilder-v2-release-notes

    Version 2 of source code of uSiteBuilder for Umbraco has been moved to GitHub (https://github.com/spopovic/uSiteBuilder). The following is a list of all the major improvements: Initial sync has been updated and is now a few times faster. Caching of loaded types/classes for faster analysis of inheritance of document types. Suppress Sync option added (configurable) Option to specify which assemblies contain your assets (document types, templates, etc.). This is an optional configuration setting which can improve initial load significantly since we would not load all assemblies from the bin folder and inspect them all when looking for your assets during the sync process. Lazy loading of property values has been implemented. uSiteBuilder can now be used on MVC projects and the model is strongly typed. Supports Umbraco CMS v6.x and v7.x projects.

    It's just some way of coding ))

    Thanks, Alex

Please Sign in or register to post replies

Write your reply to:

Draft