Switch to Typed (2sxc 16+) Selected: Dynamic (Razor14 or below)
Hybrid Razor - Code which Runs on Dnn and Oqtane
Razor is mostly HTML
+ C#
. But we need often need .net features, which can vary a bit from .net Framework and DNN, or .net core and Oqtane. This is where CmsContext.Platform.Name
is used. Read more about this in the docs.
⬇️ Result | Source ➡️
Oqtane
In some cases it's just simple to provide different cshtml
files for each platform.
Using CmsContext.Platform.Name
you can switch between files using CmsContext.Platform.Name. Here's a simple example.
⬇️ Result | Source ➡️
.net Core code = Oqtane 💧
On Oqtane or any .net core system you should see this because CmsContext.Platform.Name
was Oqtane
.
Here you can also place code which only works in Oqtane, like:
Version: 5.1.2
Razor is mostly HTML
+ C#
. But we need often need .net features, which can vary a bit from .net Framework and DNN, or .net core and Oqtane.
Preprocessor directives such as #if
, #if !
, #else
and #endif
can be used for simple switching of 2-3 lines of code. This is ideal if for example the Request
object has a slightly different signature or if you need to get a list of pages which is different in Dnn and Oqtane.
⬇️ Result | Source ➡️
Important Limitations to Preprocessors in Razor
Razor only has limited support for Preprocessor directives. For example, you cannot conditionally use @inherits
statements.
If you need this, the workaround is to create an entry-Razor which works everywhere, and two separate files which are called depending on the platform.