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.
⬇️ Result | Source ➡️
-
Settings.Get("CustomColor")
:
#E91E63F2
-
View...Get("CustomColor")
:
-
App...Get("CustomColor")
:
#E91E63F2
-
Site...Get("CustomColor")
:
Note: this will be empty, as Site doesn't have this setting
-
Global...Get("CustomColor")
:
Note: this will be empty, as Site doesn't have this setting
@inherits Custom.Hybrid.Razor14
<ul>
<li>
<div style='background-color: @Settings.Get("CustomColor")' class="color-box"></div>
<code>Settings.Get("CustomColor")</code>:
@Settings.Get("CustomColor")
</li>
<li>
@{ var source = Settings.GetSource("ViewCustom"); }
<div style='background-color: @source.Get("CustomColor")' class="color-box"></div>
<code>View...Get("CustomColor")</code>:
@source.Get("CustomColor")
</li>
<li>
@{ source = Settings.GetSource("AppCustom"); }
<div style='background-color: @source.Get("CustomColor")' class="color-box"></div>
<code>App...Get("CustomColor")</code>:
@source.Get("CustomColor")
</li>
<li>
@{ source = Settings.GetSource("SiteCustom"); }
<div style='background-color: @source.Get("CustomColor")' class="color-box"></div>
<code>Site...Get("CustomColor")</code>:
@source.Get("CustomColor") <br>
<em>Note: this will be empty, as Site doesn't have this setting</em>
</li>
<li>
@{ source = Settings.GetSource("Global"); }
<div style='background-color: @source.Get("CustomColor")' class="color-box"></div>
<code>Global...Get("CustomColor")</code>:
@source.Get("CustomColor") <br>
<em>Note: this will be empty, as Site doesn't have this setting</em>
</li>
</ul>
<style> .color-box { width: 20px; height: 20px; float: left; } </style>