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
.Name
.Type
.Version
@inherits Custom.Hybrid.RazorTyped <ol> <li> <code>.Name</code> Current platform name is: <strong>@MyContext.Platform.Name</strong> </li> <li> <code>.Type</code> Current platform type is: <strong>@MyContext.Platform.Type</strong> </li> <li> <code>.Version</code> Current platform version is: <strong>@MyContext.Platform.Version</strong> </li> </ol>
With this object you can get general information about the culture.
.CurrentCode
.DefaultCode
@inherits Custom.Hybrid.RazorTyped @using ToSic.Razor.Blade <ol> <li> <code>.CurrentCode</code> Current code culture is: <strong>@MyContext.Culture.CurrentCode</strong> </li> <li> <code>.DefaultCode</code> @if (Text.Has(MyContext.Culture.DefaultCode)) { <strong>@MyContext.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.
.Id
PortalId
.Url
.UrlRoot
@inherits Custom.Hybrid.RazorTyped @using ToSic.Razor.Blade <ol> <li> <code>.Id</code> of the current site (same as <code>PortalId</code> in DNN): <strong>@MyContext.Site.Id</strong> </li> <li> <code>.Url</code> The site url with protocol: <strong>@MyContext.Site.Url</strong> </li> <li> <code>.UrlRoot</code> The site url without a protocol: <strong>@MyContext.Site.UrlRoot</strong> </li> </ol>
Get information about the page which is the contxt for the currently running code.
TabId
Page.PageId
.Parameters
data620id=33127&variant=strong&tut=code-context&authorId=48832
.Parameters[name]
c140
@inherits Custom.Hybrid.RazorTyped @using ToSic.Razor.Blade <ol> <li> <code>.Id</code> of the current page: <strong>@MyPage.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>@MyPage.Url</strong> </li> <li> <code>.Parameters</code> all the url parameters of the page <code>@MyPage.Parameters</code> </li> <li> <code>.Parameters[name]</code> Access a specific parameter (in this case the parameter <code>c140</code> from the url) <strong> @MyPage.Parameters["c140"] </strong> </li> </ol>
Get information about the module context the code is running in.
.Guid
Note: in most cases the Block.Id and Module.Block.Id are the same, but in some cases they are different. For example when using inner-content (blocks in blocks).
@inherits Custom.Hybrid.RazorTyped @using ToSic.Razor.Blade <ol> <li> <code>.Id</code> of the current module: <strong>@MyContext.Module.Id</strong> </li> <li> <code>.Id</code> of the current block: <strong>@MyContext.Block.Id</strong> <br> <code>.Guid</code> of the current block: <br> <strong>@MyContext.Block.Guid</strong> </li> <li> <code>.Id</code> of the module-block: <strong>@MyContext.Module.Block.Id</strong> <br> <code>.Guid</code> of the current module-block: <br> <strong>@MyContext.Module.Block.Guid</strong> </li> </ol> <p> Note: in most cases the Block.Id and Module.Block.Id are the same, but in some cases they are different. For example when using inner-content (blocks in blocks). </p>
Get information about the user which is currently used by the code.
.IsSiteAdmin
.IsContentAdmin
.IsSystemAdmin
@inherits Custom.Hybrid.RazorTyped @using ToSic.Razor.Blade <ol> <li> <code>.Id</code> of the current user: <strong>@MyUser.Id</strong> </li> <li> <code>.IsSiteAdmin</code> <strong>@MyUser.IsSiteAdmin</strong> (check if the current user is a site admin) </li> <li> <code>.IsContentAdmin</code> <strong>@MyUser.IsContentAdmin</strong> (check if the current user can edit content) </li> <li> <code>.IsSystemAdmin</code> <strong>@MyUser.IsSystemAdmin</strong> (check if the current user is a super-user) </li> </ol>
Get information about the view context.
.Edition
.Identifier
Default Tutorial Page (new v16)
@inherits Custom.Hybrid.RazorTyped @using ToSic.Razor.Blade <ol> <li> <code>.Id</code> of the current view: <strong>@MyView.Id</strong> </li> <li> <code>.Edition</code> of the current view: <strong>@MyView.Edition</strong> (Get information about the edition used or return an empty string) </li> <li> <code>.Identifier</code> of the view: <strong>@MyView.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>@MyView.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>