Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
Hi!
You can create custom getters for your model properties that implements default values. There is an example of this in the Alloy templates where a default image is returned if no image has been selected.
Thank you. So simple. Dont know why I didn't figure this out myself hehe.
For others reading. This is the code from alloy:
[DefaultDragAndDropTarget]
[UIHint(UIHint.Image)]
public virtual Url Url
{
get
{
var url = this.GetPropertyValue(b => b.Url);
return url == null || url.IsEmpty()
? new Url("/Static/gfx/logotype.png")
: url;
}
set
{
this.SetPropertyValue(b => b.Url, value);
}
}
If I would use the SetDefaultValues method of the PageData object to give my properties a default value it would only affect pages that are created after this change.
I understand that if episerver would change properties on previously created pages that would be a big risk and I don't mean to change this.
What I would like to do however is to return a fallback value from the model if the property is not set.
Lets say I have this new property
This property would be the text limit of the excerpt in a search result. Since the search page is already created this would just result in the property returning 0 even if i would set it to 200 in SetDefaultValue method.
Is there any way to return a value that is not based on the property value if the property is not set? I still want to access the property CurrentPage.ExcerptLength to retrieve this. What I mean to say is that I don't want to handle the fallback value in controller or any extra read-only property on the model.
Best regards
Andreas