Views and Templates
How it Works
Read more about Templates here
The template-file is just part of the view. To be used as a view, it must be configured in the App configuration as a view, where you add things like
- Name or Thumbnail Image (for the preview when selecting the view)
- Data specs like what type of data is shown, if the data comes from a query etc.
- View Parameters to automatically show this view based on url-parameters
Views can also specify more Content-Types for using in the Header or Presentation. In addition, they could also say that the data comes from a Query instead of from user/editor input.
👉 See View Configuration
2sxc 12.02 introduces a the Identifier. This is useful in scenarios where the same Template is used in multiple views, and should result in slightly different output in each case. The Identifier let's you specify a key to differentiate which behavior the template should have.
For example: Two views are configured, one with the name
2 Columns has an Identifier
2Col the other called
3 Columns has
Your razor code can then access this on
CmsContext.View.Identifier and change what CSS classes it uses.
In theory you could also check the
Name property on
CmsContext.View.Name but that could change based on the language, which is why you should use the Identifier.
In more complex scenarios we suggest you use View Settings.
Polymorphism can be activated on views (new in v11). When you do this, you can choose between two modes
- Permission based: in this case SuperUsers get the template from the
stagingfolder while public users get the template from
liveor the primary one which was configured in the View configuration
- CSS framework based: here the view will automatically try to pick the file from the folder matching the CSS framework set by the Theme/Skin
- Switching between views based on the url
- Differences between features when using Content or App
- Protecting Views for certain users using permissions
- Hide advanced features from normal editors
- Razor Tutorial
- Introduced in 2sxc 1.0
- Automatic View-Polymorphism added in 2sxc 11
- View Identifier added in 2sxc 12.02
- View Settings added in 2sxc 12.02
- View Resources added in 2sxc 12.02