Copied to clipboard

Flag this post as spam?

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


  • AlessandroDM 21 posts 122 karma points
    Oct 17, 2017 @ 08:52
    AlessandroDM
    0

    Layout problems on nested template + query + foreach

    Hello, I have a Master template with inside a navbar and a footer, in the middle the render of the body. Created a new template for an item with the following code:


    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Azienda>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "Master.cshtml";
    }
    
    <div class="col-xs-offset-2 col-xs-8">
        @{
            var aziendaImage = Model.Content.GetPropertyValue<IPublishedContent>("aziendaImmagine");
            if (aziendaImage != null) 
            {
                <img src="@aziendaImage.Url" style="width: 100%; padding-top: 80px;"/>
            }
        }
        <h2>@Umbraco.Field("aziendaTitolo")</h2>
        <h3 style="text-align: right">@Umbraco.Field("aziendaTitolo2")</h3>
        @Umbraco.Field("aziendaDescrizione")
    
    
        @{
            var selection = Model.Content.Site().FirstChild("azienda").Children("AziendaItem")
                                .Where(x => x.IsVisible());
        }
        @foreach(var item in selection)
        {
            <div class="well">
                <div class="col-xs-10">
                    @item.GetPropertyValue("aziendaItemTitolo")
                </div>
                <a href="#@item.Name" data-toggle="collapse">
                    <div class="col-xs-2" style="text-align: right">
                        <i class="fa fa-plus" aria-hidden="true">
    
                        </i>
                    </div>
                </a>
            </div>
            <div id="@item.Name" class="collapse">
                @item.GetPropertyValue("aziendaItemDescrizione")
            </div>
        }
        <hr>
    </div>
    

    Now, if I insert the code like this, my footer crash (no idea why), but.... if I quit the last closing div, all is working again, not perfect layout, but almost image and table is displaying correctly.

    Follow the master:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = null;
    }
    
    @* the fun starts here *@
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
    
        <title>G96 - Luce Pura</title>
    
        <!-- Main CSS file -->
        <link rel="stylesheet" href="@Url.Content("~/css/bootstrap.min.css")"/>
        <link rel="stylesheet" href="@Url.Content("~/css/owl.carousel.css")"/>
        <link rel="stylesheet" href="@Url.Content("~/css/magnific-popup.css")"/>
        <link rel="stylesheet" href="@Url.Content("~/css/font-awesome.css")"/>
        <link rel="stylesheet" href="@Url.Content("~/css/responsive.css")"/>
        <link rel="stylesheet" href="@Url.Content("~/css/style.css")"/>
    
        <!-- Favicon -->
        <link rel="apple-touch-icon" sizes="57x57" href="@Url.Content("~/images/icon/apple-icon-57x57.png")">
        <link rel="apple-touch-icon" sizes="60x60" href="@Url.Content("~/images/icon/apple-icon-60x60.png")">
        <link rel="apple-touch-icon" sizes="72x72" href="@Url.Content("~/images/icon/apple-icon-72x72.png")">
        <link rel="apple-touch-icon" sizes="76x76" href="@Url.Content("~/images/icon/apple-icon-76x76.png")">
        <link rel="apple-touch-icon" sizes="114x114" href="@Url.Content("~/images/icon/apple-icon-114x114.png")">
        <link rel="apple-touch-icon" sizes="120x120" href="@Url.Content("~/images/icon/apple-icon-120x120.png")">
        <link rel="apple-touch-icon" sizes="144x144" href="@Url.Content("~/images/icon/apple-icon-144x144.png")">
        <link rel="apple-touch-icon" sizes="152x152" href="@Url.Content("~/images/icon/apple-icon-152x152.png")">
        <link rel="apple-touch-icon" sizes="180x180" href="@Url.Content("~/images/icon/apple-icon-180x180.png")">
        <link rel="icon" type="image/png" sizes="192x192"  href="@Url.Content("~/images/icon/android-icon-192x192.png")">
        <link rel="icon" type="image/png" sizes="32x32" href="@Url.Content("~/images/icon/favicon-32x32.png")">
        <link rel="icon" type="image/png" sizes="96x96" href="@Url.Content("~/images/icon/favicon-96x96.png")">
        <link rel="icon" type="image/png" sizes="16x16" href="@Url.Content("~/images/icon/favicon-16x16.png")">
        <link rel="manifest" href="@Url.Content("~/images/icon/manifest.json")">
        <meta name="msapplication-TileColor" content="#ffffff">
        <meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
        <meta name="theme-color" content="#ffffff">
        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
    
    
    
    
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    
    
    
    
    
    
    
    
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    
    
    
    
        <![endif]-->
    
    </head>
    <body>
    
    <!-- PRELOADER -->
    <div id="st-preloader">
        <div id="pre-status">
            <div class="preload-placeholder"></div>
        </div>
    </div>
    <!-- /PRELOADER -->
    
    
    <!-- HEADER -->
    <header id="header">
        <nav class="navbar st-navbar navbar-fixed-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                            data-target="#st-navbar-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="logo" href="#"><img src="@Url.Content("~/images/logo.png")" alt="" height="40px"></a>
                </div>
    
                <div class="collapse navbar-collapse" id="st-navbar-collapse">
                    <ul class="nav navbar-nav navbar-right">
                        @{
                            var selection = Model.Content.Site().Children().Where(x => x.IsVisible());
                        }
                        @foreach(var item in selection){
                            <li><a href="@item.Url">@item.Name</a></li>
                        }
                        <li style="background: #BDBDBD"><a href="#">AREA RISERVATA</a></li>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container -->
        </nav>
    </header>
    <!-- /HEADER -->
    
    @RenderBody()
    
    <!-- Footer -->
    <div class="row" style="text-align: center; background-color: #e6e6e6">
        <div class="col-xs-2">
            <img style="max-width: 100px" src="@Url.Content("~/images/logo.png")">
        </div>
        <div class="col-xs-10" style="font-size: 18px">
            <div class="col-xs-3">
                <B>AZIENDA</B>
            </div>
            <div class="col-xs-3">
                <B>SERVIZI</B>
            </div>
            <div class="col-xs-3">
                <B>PRODOTTI</B>
            </div>
            <div class="col-xs-3">
                <B>NEWS</B>
            </div>
        </div>
    </div>
    <div class="row" style="text-align: center; font-size: 12px">
        <div class="col-xs-2">
            SEDE OPERATIVA
        </div>
        <div class="col-xs-10">
            <div class="col-xs-3">
                ORGANIZZAZIONE <b>INDUSTRIALE</b>
            </div>
            <div class="col-xs-3">
                SUPPORTO ED ASSISTENZA CLIENTI
            </div>
            <div class="col-xs-3">
                INDOOR
            </div>
            <div class="col-xs-3">
                NEWSLETTER
            </div>
        </div>
    </div>
    <div class="row" style="text-align: center; font-size: 12px">
        <div class="col-xs-2">
            GARANZIA FINO A <b>"7 ANNI"</b>
        </div>
        <div class="col-xs-10">
            <div class="col-xs-3">
                VISIONE INDUSTRIALE E <b>"MISSION"</b>
            </div>
            <div class="col-xs-3">
                3D LIGHTING DESIGN
            </div>
            <div class="col-xs-3">
                OUTDOOR
            </div>
            <div class="col-xs-3">
                EVENTS
            </div>
        </div>
    </div>
    <div class="row" style="text-align: center; font-size: 12px">
        <div class="col-xs-2">
            CONDIZIONI GENERALI
        </div>
        <div class="col-xs-10">
            <div class="col-xs-3">
                COMPETENZE <b>"MANAGERIALI"</b>
            </div>
            <div class="col-xs-3">
                PROGETTAZIONE ILLUMINOTECNICA
            </div>
            <div class="col-xs-3">
                SISTEMI DI CONTROLLO
            </div>
            <div class="col-xs-3">
                NUOVI PRODOTTI
            </div>
        </div>
    </div>
    <div class="row" style="text-align: center; font-size: 12px">
        <div class="col-xs-2">
            CONDIZIONI DI SERVIZIO
        </div>
        <div class="col-xs-10">
            <div class="col-xs-3">
                ORGANIZZAZIONE <b>COMMERCIALE</b>
            </div>
            <div class="col-xs-3">
                EFFICIENTAMENTO ILLUMINOTEC.
            </div>
            <div class="col-xs-3">
                SISTEMI DI TELE-GESTIONE
            </div>
            <div class="col-xs-3">
                NUOVI PROGETTI
            </div>
        </div>
    </div>
    <!-- Scroll-up -->
    <div class="scroll-up">
        <ul>
            <li><a href="#header"><i class="fa fa-angle-up"></i></a></li>
        </ul>
    </div>
    
    
    <!-- JS -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.min.js")"></script>
    
    
    
    <!-- jQuery -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/bootstrap.min.js")"></script>
    
    
    
    <!-- Bootstrap -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.parallax.js")"></script>
    
    
    
    <!-- Parallax -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/smoothscroll.js")"></script>
    
    
    
    <!-- Smooth Scroll -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/masonry.pkgd.min.js")"></script>
    
    
    
    <!-- masonry -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.fitvids.js")"></script>
    
    
    
    <!-- fitvids -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/owl.carousel.min.js")"></script>
    
    
    
    <!-- Owl-Carousel -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.counterup.min.js")"></script>
    
    
    
    <!-- CounterUp -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/waypoints.min.js")"></script>
    
    
    
    <!-- CounterUp -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.isotope.min.js")"></script>
    
    
    
    <!-- isotope -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.magnific-popup.min.js")"></script>
    
    
    
    <!-- magnific-popup -->
    
    
    
    
    <script type="text/javascript" src="@Url.Content("~/scripts/scripts.js")"></script>
    
    
    
    <!-- Scripts -->
    
    
    </body>
    </html>
    

    The image in the top left corner of the footer disappear, the all content becomes with grey background colour as the first row of the footer. But, if I delete the last tag "" from the nested template, all the footer and content page are showing up correctly, (just... the footer becomes of 8 column size instead of full page and I get an error of a missing closing tag)

    Any idea about what I did to mess up all ? and how to fix?

  • Steve Morgan 1278 posts 4216 karma points c-trib
    Oct 17, 2017 @ 12:50
    Steve Morgan
    100

    Hi Alessandro,

    It's pretty hard to see what's gong on without all of your css. I did run your markup through an HTML validator - I'd recommend you doing this, it will really help spot the issue. It's probably a missing quote or using an opening tag as a typo when you meant a closing one!

    There are a couple of things that might be causing you issues:

    1) This line

    <a href="#@item.Name" data-toggle="collapse">
    

    This could output invalid links as the name of your node might contain a space or any other char that's not valid for an id - I'd reconsider doing this or change it to "selection-@item-id" which will be safer. (also change the corresponding id output in the child view).

    <a href="[email protected]" data-toggle="collapse">
    

    2) Inline CSS should be kept to a minimum. The height on the image in the header should be height="40" not 40px as it's inline.

    3)

        var selection = Model.Content.Site().FirstChild("azienda").Children("AziendaItem")
                                    .Where(x => x.IsVisible());
    

    I'd recommend you break this down. e.g. var homeNode = Model.Content.Site().FirstChild("azienda"); And then null check this before getting your children separately e.g. var selection = homeNode.Children("AziendaItem") Are you sure this shouldn't be "aziendaItem".

    I'd also recommend wrapping any complex inline razor in brackets (sometimes Razor gets a bit confused... so @(inlineRazorHere) is much safer).

    Also merge that foreach into the code block above - so something like:

        @{
            var homeNode = Model.Content.Site().FirstChild("azienda");
            if (homeNode != null)
            {
                var selection = homeNode.Children("aziendaItem")
                                      .Where(x => x.IsVisible());
    
                foreach (var item in selection)
                {
                    <div class="well">
                        <div class="col-xs-10">
                            @(item.GetPropertyValue("aziendaItemTitolo"))
                        </div>
                        <a href="#@item.Name" data-toggle="collapse">
                            <div class="col-xs-2" style="text-align: right">
                                <i class="fa fa-plus" aria-hidden="true">
    
                                </i>
                            </div>
                        </a>
                    </div>
    @* remember this might be better as id="[email protected]" *@
                        <div id="@item.Name" class="collapse">
                            @(item.GetPropertyValue("aziendaItemDescrizione"))
                        </div>
                }
            }
        }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies