Last active
March 11, 2020 14:12
-
-
Save kgiszewski/8863822 to your computer and use it in GitHub Desktop.
Archetype Template Use Cases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage | |
@using Archetype.Models; | |
@using Archetype.Extensions; | |
@{ | |
Layout = null; | |
} | |
//use case #1 - Covers a single Archetype | |
@foreach (var fieldset in Model.Content.GetPropertyValue<ArchetypeModel>("a1")) | |
{ | |
<!-- get a property by name --> | |
<div>@fieldset.GetValue("mntp")</div> | |
<!-- or --> | |
<!-- if using a property editor with a value converter --> | |
<div>@fieldset.GetValue<IEnumerable<IPublishedContent>>("mntp")</div> | |
} | |
//use case #2 - Covers nested Archetypes | |
@foreach (var fieldset in Model.Content.GetPropertyValue<ArchetypeModel>("a1")) | |
{ | |
<div>@fieldset.GetValue("firstName")</div> | |
<!-- get nested Archetype --> | |
foreach(var nestedFs in fieldset.GetValue<ArchetypeModel>("movieList")){ | |
<h3>@nestedFs.GetValue("title")</h3> | |
<div>@nestedFs.GetValue("text")</div> | |
} | |
} | |
//use case #2; be able to iterate over the properties, however this will not pass value through converters | |
@foreach (var fieldset in Model.Content.GetPropertyValue<ArchetypeModel>("a1")) | |
{ | |
<!-- will not go through value converters --> | |
foreach (var prop in fieldset.Properties) | |
{ | |
<div>@prop.Value</div> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of Archetype 1.0.1-beta, the models type name has been changed from
Archetype
toArchetypeModel
. Also the namespace no longer contains.umbraco