Settings in Dynamic Code ✨ new!
Settings object consolidates settings for the current scenario.
It merges settings configured in the View, App, Site, System and Presets.
The top-most setting has preference. So if a view overrides a site-setting, the view-setting will be used.
Discover More in the Razor Tutorials
We have an rich series of Razor tutorials. You should really check them out 👍.
Learn more about settings and what predefined settings exist in these docs.
There you'll learn about predefined image sizes, google maps keys and more.
Let's assume you have these View-Settings
- PrimaryColor would be
- Columns would be
- SomeApiKey would be
An these App-Settings
- PrimaryColor =
- SecondaryColor =
Then you could get these values from the
#FF0000- found it View
#00AA00- only exists in App
4- only exists in View
6n23cnhi502ceh- from App
nullas that data doesn't exist
1400as it is a preset
How it Works
Settings is a dynamic object.
Internally the Settings use the new IDynamicStack object to stack entities like sources on each other, and take the first best match.
The sources are:
- ViewCustom with View-level settings
- AppCustom/AppSystem with App-level settings
- SiteCustom/SiteSystem with Site-level settings
- GlobalCustom/GlobalSystem with System-level settings
- PresetSystem with pre-defined settings from the installation
Read more about this stack and what's in it here Settings Stack in 2sxc ✨ new!. This also includes the full list of sources and their exact names.
The order of the sources is important, as the first match will be returned. The View has priority over the App. This setup allows Views to override App-Defaults.
Accessing Settings from One Source
In rare cases you may want to access settings from a specific source - maybe to detect if it has been changed or because your template explicitly wants the App settings.
For this you can use the
GetSource(name) method like this:
- You could use
App.Settingssince ca. 2sxc 6
Settingsobject Introduced in 2sxc 12.02 to consolidate View and App Settings
Settingsobject was expanded in 12.04 to also cover global, portal and site level settings - see settings docs