Copied to clipboard

Flag this post as spam?

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


  • Topic author was deleted

    Nov 26, 2017 @ 14:56

    Tips about nested query selection and cycles FOR

    Hello, I'm developing my site and discovering everyday new questions. Today I wonder how should be a "Nested cycle FOR with nested query selection".

    Let's do an example 'cause maybe it's difficult to explain.

    I have a structure like this:

    - root
    -- slider item 1
    -- slider item 2
    -- a part of page 1
    --- 1 body of page 1
    --- 1 body of page 1
    -- a part of page 1
    --- 1 body of page 1
    -- a part of page 1
    --- 1 body of page 1
    --- 1 body of page 1
    --- 1 body of page 1
    

    the document type "a part of page 1" should be items that will appear on the same page. every nested item "1 body of page 1" is an item that is nested inside his father.

    I'm sure I constructed it in the wrong way, but my code actually looks like this:

    var selection = Model.Content.Site().FirstChild("azienda").Children("aziendaItem")
                        .Where(x => x.IsVisible());
    var index = 0;
    
    
    <div class="row azienda">
    <div class="col-sm-offset-2 col-sm-8">
        <div class="panel-group" id="accordion">
        @foreach(var item in selection){
            index++;
            var x = item.GetPropertyValue<int>("aziendaItemImmagine");
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapse@(index+1)">
                    <b>@item.GetPropertyValue("aziendaItemTitolo")</b></a>
                    </h4>
                </div>
                <div id="collapse@(index+1)" class="panel-collapse collapse">
                    <div class="panel-body">
                        <div class="col-sm-3 centerImg"><img src="@Umbraco.Media(x).Url"></div>
                        <div class="col-sm-9">@item.GetPropertyValue("aziendaItemDescrizione")</div>
    
                        @{
                            var selectionSon = Model.Content.Site().FirstChild("azienda").FirstChild("aziendaItem").Children()
                                                .Where(y => y.IsVisible());
                        }
                            @foreach(var items in selectionSon){
                                if (items.DocumentTypeAlias == "aziendaSottopaginaLayout1") {
                                    var y = items.GetPropertyValue<int>("immagineAziendaLayout1");
                                    <div class="col-sm-3 centerImg"><img src="@Umbraco.Media(y).Url"></div>
                                    <div class="col-sm-9">@items.GetPropertyValue("testoAziendaLayout1")</div>
    
                                }
                                else if (items.DocumentTypeAlias == "aziendaSottopaginaLayout2") {
                                    <div class="doctype2">Type 2</div>
                                }
                                else if (items.DocumentTypeAlias == "aziendaSottopaginaLayout3") {
                                    <div class="doctype3">Type 3</div>
                                }
                            }
                    </div>
                </div>
            </div>
        }
        </div>
    </div>
    

    my questions are:

    What should be the correct structure to work with something like this? and more important, about the query selector, "Can I pass it a variable that contains the name of the root item (title of the item) from where will be extracted the son items?"

    Sorry for my english, Thanks for helping me

    Alessandro

Please Sign in or register to post replies

Write your reply to:

Draft