Skip to content

Instantly share code, notes, and snippets.

@kgiszewski
Last active March 11, 2020 14:12
Show Gist options
  • Save kgiszewski/8863822 to your computer and use it in GitHub Desktop.
Save kgiszewski/8863822 to your computer and use it in GitHub Desktop.
Archetype Template Use Cases
@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>
}
}
@kgiszewski
Copy link
Author

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