Whenever you need to know about the current environment, you need Context information. These are the contexts you should know about:
With the ICmsContext object you can get general information about the current platform.
ICmsContext
On the older Razor14 or Razor12 it's on CmsContext.Platform.
Razor14
Razor12
CmsContext.Platform
.Name
.Type
.Version
@inherits Custom.Hybrid.Razor14 <ol> <li> <code>.Name</code> Current platform name is: <strong>@CmsContext.Platform.Name</strong> </li> <li> <code>.Type</code> Current platform type is: <strong>@CmsContext.Platform.Type</strong> </li> <li> <code>.Version</code> Current platform version is: <strong>@CmsContext.Platform.Version</strong> </li> </ol>
With this object you can get general information about the culture.
On the new RazorTyped it's on CmsContext.Culture.
RazorTyped
CmsContext.Culture
.CurrentCode
.DefaultCode
@inherits Custom.Hybrid.Razor14 @using ToSic.Razor.Blade <ol> <li> <code>.CurrentCode</code> Current code culture is: <strong>@CmsContext.Culture.CurrentCode</strong> </li> <li> <code>.DefaultCode</code> @if (Text.Has(CmsContext.Culture.DefaultCode)) { <strong>@CmsContext.Culture.DefaultCode</strong> } else { <p> The system is single language and the response is an empty string. </p> } </li> </ol>
With this object you can get general informtion about the current site.
On the older Razor14 or Razor12 it's on CmsContext.Site.
CmsContext.Site
.Id
PortalId
.Url
.UrlRoot
@inherits Custom.Hybrid.Razor14 @using ToSic.Razor.Blade <ol> <li> <code>.Id</code> of the current site (same as <code>PortalId</code> in DNN): <strong>@CmsContext.Site.Id</strong> </li> <li> <code>.Url</code> The site url with protocol: <strong>@CmsContext.Site.Url</strong> </li> <li> <code>.UrlRoot</code> The site url without a protocol: <strong>@CmsContext.Site.UrlRoot</strong> </li> </ol>
Get information about the page which is the contxt for the currently running code.
On the older Razor14 or Razor12 it's on CmsContext.Page.
CmsContext.Page
TabId
Page.PageId
.Parameters
blade=page&variant=dyn&tut=code-context&product=1&id=48832&authorId=48833
.Parameters[name]
c140
@inherits Custom.Hybrid.Razor14 @using ToSic.Razor.Blade <ol> <li> <code>.Id</code> of the current page: <strong>@CmsContext.Page.Id</strong> (<code>TabId</code> in DNN or <code>Page.PageId</code> in oqtane.) </li> <li> <code>.Url</code> the page url with protocol: <strong>@CmsContext.Page.Url</strong> </li> <li> <code>.Parameters</code> all the url parameters of the page <code>@CmsContext.Page.Parameters</code> </li> <li> <code>.Parameters[name]</code> Access a specific parameter (in this case the parameter <code>c140</code> from the url) <strong> @CmsContext.Page.Parameters["c140"] </strong> </li> </ol>
Get information about the module context the code is running in.
On the older Razor14 or Razor12 it's on CmsContext.Module.
CmsContext.Module
@inherits Custom.Hybrid.Razor14 @using ToSic.Razor.Blade <ol> <li> <code>.Id</code> of the current module: <strong>@CmsContext.Module.Id</strong> </li> </ol>
Get information about the user which is currently used by the code.
On the older Razor14 or Razor12 it's on CmsContext.User.
CmsContext.User
.IsSiteAdmin
.IsContentAdmin
.IsSystemAdmin
@inherits Custom.Hybrid.Razor14 @using ToSic.Razor.Blade <ol> <li> <code>.Id</code> of the current user: <strong>@CmsContext.User.Id</strong> </li> <li> <code>.IsSiteAdmin</code> <strong>@CmsContext.User.IsSiteAdmin</strong> (check if the current user is a site admin) </li> <li> <code>.IsContentAdmin</code> <strong>@CmsContext.User.IsSiteAdmin</strong> (check if the current user can edit content) </li> <li> <code>.IsSystemAdmin</code> <strong>@CmsContext.User.IsSystemAdmin</strong> (check if the current user is a supe-user) </li> </ol>
Get information about the view context.
On the older Razor14 or Razor12 it's on CmsContext.View.
CmsContext.View
.Edition
.Identifier
Default Tutorial Page (new v16)
@inherits Custom.Hybrid.Razor14 @using ToSic.Razor.Blade <ol> <li> <code>.Id</code> of the current view: <strong>@CmsContext.View.Id</strong> </li> <li> <code>.Edition</code> of the current view: <strong>@CmsContext.View.Edition</strong> (Get information about the edition used or return an empty string) </li> <li> <code>.Identifier</code> of the view: <strong>@CmsContext.View.Identifier</strong> <br> An optional identifier which the View configuration can provide. Use this when you want to use the same template but make minor changes based on the View selected (like change the number of columns). Usually you will use either this OR the Settings: </li> <li> <code>.Name</code> of the view <code>@CmsContext.View.Name</code> <br> Name of the view as configured - note that because of i18n it could be different depending on the language. To clearly identify a view, use the Identifier or use Settings: </li> </ol>