Every view/template receives prepared data, either entered by the user on this page, or provided through a query. It can contain many items - so to get the list, use AsList(Data)
.
If a view has many items assigned (called a list) these should be retrieved from Data
- if you don't specify a stream, it's treated as Data["Default"]
. You will usually want to convert it to a dynamic list using AsList(...)
. This example also uses Text.Has(...)
to only show a picture if it really has a mugshot.
-
-
⬇️ Result | Source ➡️
Loop persons which were added to this view
-
Douglas Adams
-
Terry Pratchett
-
Neil Gaiman
@inherits Custom.Hybrid.Razor14
@using ToSic.Razor.Blade
<h4>Loop persons which were added to this view</h4>
<ul>
@foreach (var person in AsList(Data)) {
<li>
@if (Text.Has(person.Mugshot)) {
@Kit.Image.Img(person.Field("Mugshot"), settings: "Square", width: 50, imgClass: "rounded-circle")
}
@person.FirstName @person.LastName
</li>
}
</ul>
View Configuration
This is how this view would be configured for this sample.
- Query: QuickRef-Persons-Selected
Details for Query: QuickRef-Persons-Selected
This query will retrieve Terry Pratchett on one stream, and 3 other persons an another stream.