-
Notifications
You must be signed in to change notification settings - Fork 3
DocTypes
APE generates a class file for each DocType in Umbraco.
Lastly APE generates a file wrapping all the DocType classes in a singleton pattern for easy access.
As with all APE related stuff, using DocTypes is super easy.
You access it via the DocTypes class:
DocTypes.Frontpage
This returns the generated class for the Frontpage. Which is also implicit cast to a string containing the DocTypeAlias. Example:
if(CurrentPage.DocumentTypeAlias == DocTypes.Frontpage)
From the DocType class you have access to all your DocType properties.
DocTypes.Frontpage.Header
This returns a propertyClass, which is also implicitly cast to the Header alias for the Frontpage DocType. This propertyClass comes into play later.
Now naturally we map the same inheritance in our classes as the DocType have in Umbraco.
With APE we can extract a lot of information about your properties and we use this information to further ease your development.
We map the DataType and Description as summary on the properties, telling you a little more about the property you are using.
When you get the data from Umbraco you do as you always have, by passing the propertyalias:
CurrentPage.GetPropertyValue(DocTypes.Frontpage.BodyText)
Normally this would return the BodyText property as a string.
But we made an extension on .GetPropertyValue which we pass our propertyClasses to.
APE knows this is a RichText Editor and therefore returns an IHtmlStringProperty to the extension.
This extension calls a method on the propertyClass called Map() which return the property as IHtmlString.
We have made mappers for most of the native DataTypes in Umbraco. So a ContentPicker now actually returns an IPublishedContent rather than a nodeId.
IPublishedContent cookiePage = CurrentPage.GetPropertyValue(DocTypes.Frontpage.CookiePage);
APE maps the DataTypes based on the Id or Alias from Umbraco and matches it up against the Classes that we made.
An example:
[UmbracoPropertyId("UMBRACO.TINYMCEV3")]
public class HtmlStringProperty : DocTypeProperty<IHtmlString>
{
public override IHtmlString Map(IPublishedContent content, bool recursive = false)
{
return new HtmlString(content.GetPropertyValue<string>(this.Alias, recursive, string.Empty));
}
}The meta tag is the DataType alias from Umbraco. Using reflection we match the two up and therefore knows it is this type. Then we override the default Map and in this case put it in a HtmlString.
You can make your own DataTypeProperties and tell APE to return it as your own DataType.
In the future APE will find your code, match the meta tag with Umbraco and return it just the way you want it.
For now however you have to specify it. Example:
CurrentPage.GetPropertyValue(DocTypes.Frontpage.CustomProperty.As<CustomDataTypeProperty>)