Configuring ModelsBuilder to work with Fallback.To...
# help-with-umbraco
b
I know I can use
Model.Value<string>("alias", fallback: Fallback.ToAncestors)
but is there a straightforward way to call ModelsBuilder properties with a fallback parameter? I could change the generated class, but I'm hoping if there's a more permanent option. Incidentally I tried using
Model.ValueFor(x => x.Alias, fallback: Fallback.ToAncestors)
as per [the docs](https://docs.umbraco.com/umbraco-cms/fundamentals/design/rendering-content), which would be fine, but it throws an error (when falling back to an ancestor): NotSupportedException: Fallback PublishedValueFallback does not support fallback code '3' at element level.
I worked around this by making a custom 'ModelsBuilder-like' class with with the fallback-enabled call in the prop getters, e.g.
public virtual decimal BaseFontSize => this.Value<decimal>(_publishedValueFallback, "baseFontSize", fallback: Fallback.ToAncestors);
b
@Barry Fogarty the valuefor doesnt work for elements types, it is why compositions shouldn't be elements types 😉 you can workaround it by making custom extensions which I dont recommend 🙂
27 Views