#2 Deep dive into the Settings stack
Settings in 2sxc 🆕 in 12.03
Settings allow your code to use predefined settings across all apps and sites.
And they allow you to overide a setting at any level of the application.
You can read more about the settings in the docs 📕.
Settings Stack
Settings are stacked in a way that the View-settings have a higher priority than App-settings, which has a higher priority than Site, etc.
In rare cases you may want to explicitly check for a setting at a specific place in the stack.
This example has a setting called CustomColor
which is set at App and View level. Using GetSource(...)
we can access a specific source.
-
@Settings.CustomColor
: #4CAF50CC
-
@Settings.GetSource("View").CustomColor
:
-
@Settings.GetSource("App").CustomColor
:
-
@Settings.GetSource("Site").CustomColor
:
Note: this will be empty, as Site doesn't have this setting)
-
@Settings.GetSource("Global").CustomColor
:
Note: this will be empty, as Site doesn't have this setting)
#2 Deep dive into the Settings stack
@inherits Custom.Hybrid.Razor14
<!-- unimportant stuff, hidden -->
<hr>
Settings Stack Settings are stacked in a... <!-- unimportant stuff, hidden -->
<ul>
<li>
<div style='width: 20px; height: 20px; float: left; background-color: @Settings.CustomColor'></div>
<code>@@Settings.CustomColor</code>: @Settings.CustomColor
</li>
<li>
<div style='width: 20px; height: 20px; float: left; background-color: @Settings.GetSource("View").CustomColor'></div>
<code>@@Settings.GetSource("View").CustomColor</code>: @Settings.GetSource("View").CustomColor
</li>
<li>
<div style='width: 20px; height: 20px; float: left; background-color: @Settings.GetSource("App").CustomColor'></div>
<code>@@Settings.GetSource("App").CustomColor</code>: @Settings.GetSource("App").CustomColor
</li>
<li>
<div style='width: 20px; height: 20px; float: left; background-color: @Settings.GetSource("Site").CustomColor'></div>
<code>@@Settings.GetSource("Site").CustomColor</code>: @Settings.GetSource("Site").CustomColor <br>
<em>Note: this will be empty, as Site doesn't have this setting)</em>
</li>
<li>
<div style='width: 20px; height: 20px; float: left; background-color: @Settings.GetSource("Global").CustomColor'></div>
<code>@@Settings.GetSource("Global").CustomColor</code>: @Settings.GetSource("Global").CustomColor <br>
<em>Note: this will be empty, as Site doesn't have this setting)</em>
</li>
</ul>
<!-- unimportant stuff, hidden -->