#2 Place platform specific code in different child Razor files
Platform Specific Sub-Razor-Files
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.
Output
.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: 4.0.2
#2 Place platform specific code in different child Razor files
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 --> <div @Sys.PageParts.InfoWrapper()> @Html.Partial("../shared/DefaultInfoSection.cshtml") <div @Sys.PageParts.InfoIntro()> <h2>Platform Specific Sub-Razor-Files</h2> <p> In some cases it's just simple to provide different <code>cshtml</code> files for each platform. </p> <p> Using <code>CmsContext.Platform.Name</code> you can switch between files using CmsContext.Platform.Name. Here's a simple example. </p> </div> </div> @Html.Partial("CodeSwitching." + CmsContext.Platform.Name + ".cshtml") @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })