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> | |
} | |
} |
Users of Archetype 0.5.1-alpha and before will have to append a .Fieldsets
to the end of Model.Content.GetPropertyValue<Archetype>("a1")
As of Archetype 1.0.1-beta, the models type name has been changed from Archetype
to ArchetypeModel
. Also the namespace no longer contains .umbraco
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In example 3, you can change:
var nested = fieldset.GetValue<Archetype>(prop.Alias);
to just
var nested = prop.GetValue<Archetype>();