Skip to main content
Home  › ... 2sxc Apps

Hybrid Razor Templates

Tutorial Home

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.

Requirements
Resources


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")

Source Code of this file

Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code

@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 -->