Developer forum

Forum » Swift » Website setting default value

Website setting default value

Johan Lang
Johan Lang
Reply

Hi,

If I create a new website setting, ie TestCount,  as int32 and set the default value to 30 and save it and close, the website setting is not set by the default value, it's 0.

Website setting:

 

In cshtml I can get the website setting value with:

int count = Pageview.AreaSettings.GetInt32("TestCount");

But how can I set a website setting vaule in cshtm?

I have trie with:
Model.Area.Item.Fields.Where(x => x.SystemName == "TestCount").SingleOrDefault().Value
but Value has only the Get property


Replies

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply

Hi Johan,
it could be used API: Item service  to change the website settings: https://doc.dynamicweb.com/apix/api/Dynamicweb.Content.ItemService.html

 if (Model.Area.Item != null)
 {
    var websiteSettings = Dynamicweb.Services.Items.GetItem(Model.Area.ItemType, Model.Area.ItemId);
    websiteSettings["TestCount"] = 32;
    Dynamicweb.Services.Items.SaveItem(websiteSettings);
 }

Kind regards,
Vladimir

 
Johan Lang
Johan Lang
Reply

Ok, thanks!

What about to set a defult value in website setting, is it a bug that it not work?

 

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply

Hi Johan,

The default value is not automatically written to DB. 
When a new field is added to an already existed item with default value - this value will be shown in edit form by default and it is required to save it to store in DB.


Kind regards,

Vladimir

 

You must be logged in to post in the forum