Show already existing items in list

May 27, 2015 at 1:31 PM
I created a content type and added several records before I created a Razor template, with list enabled.
However, the template only displays the first record in the content type. How do I make it loop through all of them?
Here's my template:
<ul class="cbp_tmtimeline">
 @foreach(var e in List) {
 var Content = e.Content;
 var Presentation = e.Presentation;

    <li>
@Content.Toolbar
    <time class="cbp_tmtime" datetime="@Content.Year">@Content.Year</time>
    <div class="cbp_tmicon @Presentation.CSSclass">
    </div>
    <div class="cbp_tmlabel">
    
        @Html.Raw(Content.Description)

    </div>
</li>
}
</ul>
May 28, 2015 at 5:05 PM
Figured it out, see edited code in quote.
@using ToSic.Eav.DataSources
@{ 
    int rowCounter = 0;
    var mid = Dnn.Module.ModuleID.ToString();
    var allItems = CreateSource<EntityTypeFilter>();
    allItems.TypeName = "Event";
    
    }

<ul class="cbp_tmtimeline">
 @foreach (var dict in allItems.List) {
        var Content = AsDynamic(dict.Value);
        var Presentation = AsDynamic(dict.Value);

    <li>
@Content.Toolbar
    <time class="cbp_tmtime" datetime="@Content.Year">@Content.Year</time>
    <div class="cbp_tmicon @Presentation.CSSclass">
    </div>
    <div class="cbp_tmlabel">
    
        @Html.Raw(Content.Description)

    </div>
</li>
}
</ul>
Now my presentation doesn't work though.
As it is above, @Presentation.CSSclass generates nothing.
If I remove "var Presentation = AsDynamic(dict.Value);" it just uses the demo presentation data no matter which record is actually selected.
May 28, 2015 at 5:08 PM
This is what I'm trying to create:
http://www.rcu.msstate.edu/HOME/AbouttheRCU/HistoryoftheRCUApp.aspx

I could also use some help ordering every event by year. Tacking on an OrderBy statement at the end of allItems.List doesn't work.
Jun 2, 2015 at 3:19 PM
Here's my working template, ordered by year of each event.
If the event has Publications, an accordion style list of those publications is displayed.

@using ToSic.Eav.DataSources
@{ 
    int rowCounter = 0;
    var mid = Dnn.Module.ModuleID.ToString();
    var allItems = CreateSource<EntityTypeFilter>();
    allItems.TypeName = "Event";
    var sorted = CreateSource<ValueSort>(allItems);
        sorted.Attributes = "Year";  
        Data.In.Add("Event", sorted["Default"]);
    }

    
<ul class="cbp_tmtimeline">

 @foreach (var dict in sorted.List) {
        var Content = AsDynamic(dict.Value);
        var Pubs = ((ToSic.Eav.IEntity)AsEntity(Content))
            .Relationships.AllParents
            .Where(c => c.Type.Name == "Publications");



    <li>
@Content.Toolbar
    <time class="cbp_tmtime" datetime="@Content.Year">@Content.Year</time>
    <div class="cbp_tmicon @Presentation.CSSclass">
    </div>
    <div class="cbp_tmlabel">

@if(Content.Publications.GetType() != typeof(String) && Content.Publications.Count > 0) { 
            var publ = Content.Publications[0]; 
            <div class="accordion history-accordion" id="pubs-@Content.Year">
            <div class="accordion-group">
                <div class="accordion-heading">
                    <em class="micon-arrow-down-7"></em><a class="accordion-toggle collapsed" href="#collapse-@Content.Year" data-toggle="collapse" data-parent="#pubs-@Content.Year">Published by the RCU in @Content.Year:</a>
                </div>
<div class="accordion-body collapsed collapse" id="collapse-@Content.Year">
                    <div class="accordion-inner">
<ul>

    @foreach(var publi in Content.Publications) {
      var Public = AsDynamic(publi);
<li><a href="@Public.issuu" target="_blank">@Public.Name</a></li>
}
</ul>
</div>
</div>
</div>
</div>
}
else {
        @Html.Raw(Content.Description)
}

    </div>
</li>
}
</ul>
Still got to figure out the icons. I'm using separate presentation using the Icon content type, which has the CSSclass field. It isn't working.
Coordinator
Jun 2, 2015 at 7:10 PM
@Amanda I'm not sure of what you're doing exactly, but I think there's another angle you have to look at.

Using Presentation (providing separate display information in addition to the content-item) is something which usually only works for content which the user adds/edits on this module instance. Why? Because if you're retrieving a list of items in DB-mode, then the editor never had the opportunity to add presentation-details to say "the second item is red" because if you just query data from "all data" then those items were never coupled to instance-specific presentation information.

But no matter what you are attempting - i'm sure it can be done. Just probably not like this :)

Could you take a few minutes to describe in real words what you're doing? like "i have database of videos and each video ..." etc. Please be specific, that way I can help you better :)
Jun 2, 2015 at 8:26 PM
I am creating a timeline. The finished product should look something like this: http://www.rcu.msstate.edu/history.aspx
(That's a static version.)

When you add an event to the timeline, you select a relevant Icon for that event via an entity field. The Icon content type has a CSSclass field I want to display in this div:
<div class="cbp_tmicon [CSSclass]">
Thanks!
Jun 2, 2015 at 9:18 PM
HI Amanda

I have to login for the last so cant see that one

but since you are using all items you cant use presentation as presentation is set on an item when its added to a module there is no presentation avaiable if you get all the data not referenced to a module

In this case I would make an icon content type and add this one as an entity nd then get the class from there and ot from the presentation

Armand
Jun 2, 2015 at 9:25 PM
I changed the permissions on that page so you can see it now.

That is how the Icon is set up - it's an entity. I'm just having trouble getting the class to work in the template.
Jun 2, 2015 at 9:27 PM
HI Amanda can you export the app so we can import and check it out?

Armand
Jun 2, 2015 at 9:32 PM
Coordinator
Jun 2, 2015 at 10:03 PM
I agree with nokikos solution - just create a related entity and use that. I'm actually guessing you did that, but got confused with presentation.

So your code will more likely be something like @Content.Icon[0].CSSClass But let's wait till nokiko looks at your app

@nokiko - thanks for helping :)
Jun 3, 2015 at 8:06 AM
Hi Amanda

If you replace
@Presentation.CSSclass
with
@Content.Icon[0].CSSClass
you are good to go


Armand
Jun 3, 2015 at 2:46 PM
PERFECT. Thank you.