November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Can you give sample code of such property which reuses Start page properties?
Here is an example :-
If childpage property is not set I set the StartPage Property..
ChildPage.Property = ChildPage.Property == null ? StartPage.PropertyName :ChildPage.Property
And where do you run this code? In some event, controller's action or in Property's getter?
I override the Below Method:-
The code gets the startpage property value but after I update the update is not reflected in the property.
public override void SetDefaultValues(ContentType contentType)
{
base.SetDefaultValues(contentType);
LanguageHeading = !string.IsNullOrEmpty(startPage.Property["LanguageHeading"].ToString()) ? startPage.Property["LanguageHeading"].ToString() : string.Empty;
}
SetDefaultValues is called only once when the page (or other IContent) is created. It is not called when you save the page later.
Instead I suggest you to handle this in the property itself:
public class MyPage : PageData { public string DefaultHeading = "My heading"; [Display(Order = 20)] [CultureSpecific] public virtual string LanguageHeading { get { return this.GetPropertyValue(p => p.LanguageHeading) ?? DefaultHeading; } set { this.SetPropertyValue(p => p.LanguageHeading, value); } } }
Is startPage or StartPage a static variable or property? If so, that's probably the problem. You need to fetch the startpage every time, which is not a problem since it's cached.
Thanks Johan and Maris for the answers.
@Maris
Since client has created many subsites (close to 40) all the default values has been set on live , i.e. value from start page while creating the page during override of SetDefaultValues() method .
So properties will never be null or empty now . My requirement was IF property is not set in Subsite for that page it should get from Startpage of the page. Since now all the properties has some value how do I change the logic now ??
@Johan
Yes I had made static property ,now I changed that . Thanks for pointing it .
Now you can create ScheduledJob which goes through all pages and resets that property to null if it equals to start page property's value. It might look something like this in the ScheduledJob's Execute method:
var allPages = GetAllSitePages(); foreach(var page in allPages) { if(page.MyProperty == startPage.MyProperty) { page.MyProperty = null; _contentRepository.Save(page); } }
Hi All,I am resusing some of my property values from start page into my other pages as reusable component.
But when I update the value on start page its not updated on other pages .It still has the old value. Do anyone faced this issue before , some kind of caching?