#5 Look into a Content-Type
Requirements
Resources
Look at the Content-Type of something
In some advanced cases you want to find out information about a specific content-type.
Content-Type Information
Initial Code
The following code runs at the beginning and creates some variables/services used in the following samples.
- Type object: ToSic.Eav.Data.ContentType 🔗
- Type Name: "Persons"
- Type Internal Name: "e748cf30-7849-46f1-a331-f181ba047cb2"
- Type of the Awards field: "Entity"
-
Values in the
Sex
field (String) dropdown- Unknown = ''
- Male = 'm'
- Female = 'f'
- Non-binary = 'nb'
Properties / Attributes
Read more about attributes in the docs 🔗
-
First Name
(FirstName,
String
= typeId 6) -
Last Name
(LastName,
String
= typeId 6) -
Birthday
(Birthday,
DateTime
= typeId 2) -
Mugshot
(Mugshot,
Hyperlink
= typeId 4) -
Awards
(Awards,
Entity
= typeId 3) -
Sex
(Sex,
String
= typeId 6)
#5 Look into a Content-Type
Source Code of this file
Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code
@inherits Custom.Hybrid.Razor14 @using ToSic.Razor.Blade; @using System.Linq; @using System.Collections.Generic; @using ToSic.Eav.Data; <!-- unimportant stuff, hidden --> <div @Sys.PageParts.InfoWrapper()> @Html.Partial("../shared/DefaultInfoSection.cshtml") <div @Sys.PageParts.InfoIntro()> <h2>Look at the Content-Type of something</h2> <p> In some advanced cases you want to find out information about a specific content-type. </p> </div> </div> <h3>Content-Type Information</h3> @{ var type = AsEntity(Content).Type; var attributes = type.Attributes as IEnumerable<IContentTypeAttribute>; var sexAttr = attributes.First(t => t.Name == "Sex"); // Check the metadata for the DropdownValues in the type @string-dropdown var sexDropdown = sexAttr.Metadata.GetBestValue<string>("DropdownValues", "@string-dropdown"); } <ol> <li>Type object: <a href="https://docs.2sxc.org/api/dot-net/ToSic.Eav.Data.IContentType.html" target="_blank">@type 🔗</a></li> <li>Type Name: "@type.Name"</li> <li>Type Internal Name: "@type.StaticName"</li> <li>Type of the Awards field: "@attributes.First(t => t.Name == "Awards").Type"</li> <li> Values in the <code>Sex</code> field (@sexAttr.Type) dropdown <ul> @foreach (var s in sexDropdown.Split(new [] { '\r', '\n' })) { var parts = s.Split(':'); <li>@parts[0] = '@(parts.Length > 0 ? parts[1] : "")'</li> } </ul> </li> </ol> <h3>Properties / Attributes</h3> <p> Read more about <a href="https://docs.2sxc.org/api/dot-net/ToSic.Eav.Data.IContentType.html#ToSic_Eav_Data_IContentType_Attributes" target="_blank">attributes in the docs 🔗</a> </p> <ul> @foreach (var attr in type.Attributes) { <li> @* This will get the label from the metadata entity *@ @(attr.Metadata.GetBestValue<string>("Name", "@All")) (@attr.Name, <code>@attr.Type</code> = typeId @((int)attr.Type)) </li> } </ul> @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })