• Basics
  • Abyss
  • Web APIs
  • C# & Razor
  • .net API
  • JS & TS API

    Show / Hide Table of Contents

    Views and Templates

    you are here (click to zoom) - discover the stack

    Views are what the user will see - and contains things like Html, CSS, Javascript and data from the content.

    How it Works

    Views configure what templates are combined with what Content-Type to then produce an output.

    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

    1. Name or Thumbnail Image (for the preview when selecting the view)
    2. Data specs like what type of data is shown, if the data comes from a query etc.
    3. View Parameters to automatically show this view based on url-parameters
    Tip

    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.

    View Configuration

    👉 See View Configuration

    View Identifier

    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 3Col. 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.

    View Settings

    👉 See View Settings (Advanced ⚠)

    View Resources

    👉 See View Resources (Advanced ⚠)

    View Polymorphism

    Polymorphism can be activated on views (new in v11). When you do this, you can choose between two modes

    1. Permission based: in this case SuperUsers get the template from the staging folder while public users get the template from live or the primary one which was configured in the View configuration
    2. 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

    Advanced Topics

    • 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

    History

    1. Introduced in 2sxc 1.0
    2. Automatic View-Polymorphism added in 2sxc 11
    3. View Identifier added in 2sxc 12.02
    4. View Settings added in 2sxc 12.02
    5. View Resources added in 2sxc 12.02
    • Improve this Doc
    Back to top Generated by DocFX