Using a Razor token for entity field in a class attribute

Jan 14, 2015 at 3:10 PM
I'm using this code in my Razor template
<div style="display: inline-block; opacity: 1;" class="@Content.Category mix item col-md-3 mix_all">
But the HTML it's generating is this
<div style="display: inline-block; opacity: 1;" class="System.Collections.Generic.List`1[ToSic.SexyContent.DynamicEntity] mix item col-md-3 mix_all">
Category is an entity field; each item should have a different category as one of the classes in that div.
Jan 14, 2015 at 3:34 PM
OK, I changed the class to @Presentation.DataFilter (the sole field in my Category content type) and that is now generating the correct class name.

This is what I'm working on: http://apps.rcu.msstate.edu/Research-and-Evaluation/Reports.aspx

Now the problem is that it's giving both items in my list the same class of "annualMDE", but one of them SHOULD be "annualORED".

I have tried tinkering with the template settings, and even going into that one item's settings and entering in "annualORED" into the Presentation setting doesn't change it from "annualMDE". (See screenshot.)
Coordinator
Jan 14, 2015 at 4:08 PM
@Amanda

Related properties are always a list - because you could have 0, 1 or many items. So if you stick to the related entities, the correct syntax would be something like
@Content.Category[0].Title
When using the second pattern (presentation), remember that the initial Content and Presentation only contain the 1st item. When you loop through the content items, there is usually a bit of code like this:
foreach(e in List...)
{
  var c = e.Content;
}
You should extend it a bit more like this
foreach(e in List...)
{
  var c = e.Content;
  var p = e.Presentation;
}
Love from Switzerland,
Daniel
Jan 14, 2015 at 6:26 PM
Edited Jan 14, 2015 at 6:28 PM
I am not sure how to work that into the loop I already have set up. The whole presentation vs. content feature of 2sxc really baffles me. I would love if you would do a video dedicated to it someday! I also have trouble understanding why there are different tokens for Content & ListContent, etc. I see now I think I used some of both in this template.

This is the entire loop. The problematic token is on the 3rd line. Thanks for your help.
@foreach(var e in List) {
var Content = e.Content;
    <div style="display: inline-block; opacity: 1;" class="@Presentation.DataFilter mix item col-md-3 mix_all">
@Html.Raw(Content.Toolbar)

    <div class="portfolio-item-container">
    <div class="portfolio-item">

        <img src="@Content.Thumbnail" class="item-image" alt="@Content.Name cover" />
        <a href="#" class="overlay zoom">
        <div class="preview-links">
            <span class="zoom">
            <em class="micon-docs"></em>
            </span>
        </div>
        </a>
    </div>  
<div class="item-meta-container">
<h4 class="item-title">@Content.Name</h4>
        
    <ul class="categories">
        <li>@ListContent.Author</li>
    </ul>
<div class="item-desc hide">
<p>@Html.Raw(Content.Description)</p>

            <p>
            <a href="@Content.File" class="rox-short-button large maroon"><em class="micon-download"></em> Download PDF</a>
            <a href="@Content.issuu" class="rox-short-button large maroon"><em class="micon-book-4"></em> Read online</a>
            </p>
</div>
</div>
</div>
</div>
}
Coordinator
Jan 15, 2015 at 6:30 AM
Add my line 3
@foreach(var e in List) {
var Content = e.Content;
var Presentation = e.Presentation;
    <div style="display: inline-block; opacity: 1;" class="@Presentation.DataFilter mix item col-md-3 mix_all">
@Html.Raw(Content.Toolbar)

    <div class="portfolio-item-container">
    <div class="portfolio-item">

        <img src="@Content.Thumbnail" class="item-image" alt="@Content.Name cover" />
        <a href="#" class="overlay zoom">
        <div class="preview-links">
            <span class="zoom">
            <em class="micon-docs"></em>
            </span>
        </div>
        </a>
    </div>  
<div class="item-meta-container">
<h4 class="item-title">@Content.Name</h4>
        
    <ul class="categories">
        <li>@ListContent.Author</li>
    </ul>
<div class="item-desc hide">
<p>@Html.Raw(Content.Description)</p>

            <p>
            <a href="@Content.File" class="rox-short-button large maroon"><em class="micon-download"></em> Download PDF</a>
            <a href="@Content.issuu" class="rox-short-button large maroon"><em class="micon-book-4"></em> Read online</a>
            </p>
</div>
</div>
</div>
</div>
}
Jan 16, 2015 at 3:45 PM
PERFECT!! Thank you!