Razor will not loop

Aug 21, 2014 at 5:11 AM
Edited Aug 21, 2014 at 5:12 AM
I've cut my test template down to the bone (below)
<div> <ul> @foreach(var i in List) { var item = i.Content; <li class="sc-element"> @Content.Toolbar @item.Product_Name, @item.Product_Description </li> } </ul> </div> But I still cannot get a list of the items I already have loaded in this list. I have enabled list in 'Manage Templates'.
I can create a new item using the toolbar and it will display but I cannot display items that have been created in the list through the admin panel.
What am I doing wrong?!
Aug 21, 2014 at 5:26 AM
I just tried this template and it worked for me
@{ 
    int rowCounter = 0;
    var mid = Dnn.Module.ModuleID.ToString();  
}
<div>
    <ul>
        @foreach (var e in List)
        {
            var Content = e.Content;
            var cid = Content.EntityId;         
            
            <li> @Content.Toolbar @Content.Product_Name, @Content.Product_Description </li>
      
            rowCounter = rowCounter + 1;
        }

    </ul>
</div>
Developer
Aug 21, 2014 at 5:42 AM
2SexyContent provides two different ways of adding new items:
  1. Add a demo item - when you add a new item to the list (the first + symbol), 2SexyContent will add a demo-item. If you edit the demo-item, 2SexyContent will display an empty dialog to create a new item. You can set the demo item for Content in the template settings.
    If you see entries like "(no demo row)" in the "Edit List"-Dialog, you have probably no demo item set for the current template. The template won't display these items, and this might be the problem in your case.
  2. Add a new item directly (the second + symbol) - this will open the empty dialog directly, and create a new item when saving.
Aug 21, 2014 at 5:46 AM
Edited Aug 21, 2014 at 5:48 AM
Yes this works.. (I've added EntityId to each item line) for the items added via the tool bar

Mince, Mince Pie, 512
Cherry, Cherry Pie, 538

But go to the same list in the admin panel and I see
    EntityId    RepositoryId    EntityTitle IsPublished Product_Name    Product_Description Product_Image   Product_Category
Edit Delete 512 512 Mince Mince Mince Pie File:205 516
Edit Delete 537 537 Peach & Passionfruit Peach & Passionfruit Peach & Passionfruit Pie
Edit Delete 538 538 Cherry Cherry Cherry Pie 517


Why is 'Peach & Passionfruit' not showing on my page? (And yes, it is published)
Aug 21, 2014 at 5:59 AM
Did you add that one directly from within the manage content type, then its not linked to your module so you will not see it.

This is a different template that just displays all items no matter where it was added, change SampleProduct to your content type name and see if you get the full list now
@using ToSic.Eav.DataSources
@{ 
    int rowCounter = 0;
    var mid = Dnn.Module.ModuleID.ToString();

    var allItems = CreateSource<EntityTypeFilter>();
    allItems.TypeName = "SampleProduct";
}
<div>
    <ul>

       @foreach (var dict in allItems.List)
        {
            var Content = AsDynamic(dict.Value);
            var cid = Content.EntityId;      
            
            <li> @Content.Toolbar @Content.Product_Name, @Content.Product_Description </li>
      
            rowCounter = rowCounter + 1;
        }

    </ul>
</div>
Marked as answer by 2sicDev on 8/22/2014 at 8:16 AM
Developer
Aug 21, 2014 at 6:08 AM
Inside the Admin panel, you will see all entities that were added to any module (and also those not added to any module) on the current portal. Every module can have some of these entities assigned.

If you click "Edit List" in the module actions of your list module, you will see the entities assigned to the module. All the other enties won't be displayed by the template, unless you add them to the module's list.

@nokikos example is a way for getting the global list of entities (of a specific type). This way you will see the same entities in every instance of the template.
Coordinator
Aug 21, 2014 at 6:10 AM
Note that a new feature in 6.2 makes the initial code a bit simpler. see App.Data. Instead of
@{ 
    int rowCounter = 0;
    var mid = Dnn.Module.ModuleID.ToString();

    var allItems = CreateSource<EntityTypeFilter>();
    allItems.TypeName = "SampleProduct";
}
you can now do
@{ 
    int rowCounter = 0;
    var mid = Dnn.Module.ModuleID.ToString();

    var allItems = App.Data["SampleProduct"];
}
Marked as answer by 2sicDev on 8/22/2014 at 8:16 AM
Aug 21, 2014 at 8:24 AM
Thanks for the feedback. I now have a clearer understanding this modules functionality.