Hybrid Templates using Preprocessor Directives
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.
When working with normal .cs
files #if
, #if !
, #else
and #endif
can be used due
to them being compiled by 2sxc.
Using CmsContext.Platform.Name
you can switch between files using CmsContext.Platform.Name. Here's a simple example.
NON .net Core code = Dnn ☢
On Dnn you'll see this because CmsContext.Platform.Name
was Dnn
.
Here you can also place code which only compiles in DNN, like:
PortalId = 0
@Html.Partial("_410-compiler-preprocessor.PartInfo." + CmsContext.Platform.Name + ".cshtml")
@inherits Custom.Hybrid.Razor14
<!-- unimportant stuff, hidden -->
Hybrid Templates using Preprocessor... <!-- unimportant stuff, hidden -->
<hr>
@Html.Partial("_410-compiler-preprocessor.PartInfo." + CmsContext.Platform.Name + ".cshtml")
<!-- unimportant stuff, hidden -->