Partial Macro Views
Partial view macros are the way to render the macro component in the end user UI - it is build following same princples as other templates and partial views with some additional features. They are the best ay to create dynamically repeatitive rendered components in your portal
View/Model Type
All partial view macro views inherit from Umbraco.Web.Macros.PartialViewMacroPage
and as such, the header of each partial view macro file will have this syntax:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
The model type for a partial view macro is Umbraco.Web.Models.PartialViewMacroModel
which contains all of the properties you will need to
render out content as well as some additional properties about the macro itself: MacroName
, MacroAlias
, MacroId
, and MacroParameters
.
Accessing content
The syntax in Partial View Macros is 100% on par with the Templates syntax, in fact they are driven by the exact same engine as MVC Views.
You can use @CurrentPage, @Model.Content, ...
Accessing macro parameters
You can access the macro's parameters using the MacroParameters
property on the model which is of type IDictionary<string, object>
var myParam = Model.MacroParameters["aliasOfTheMacroParameter"];
or via the typed GetParameterValue method in Umbraco.Web.Models namespace
var myParam = Model.GetParameterValue<string>("aliasOfTheMacroParameter");
and with default value fallback
var myParam = Model.GetParameterValue<string>("aliasOfTheMacroParameter", "default value if parameter value has not been set");