ZauberCMS
  • 🪄Welcome to ZauberCMS
  • Getting Started
    • 💡Quick Start
      • Databases
  • Creating A Website
    • 📹Website Build Video Tutorial
    • Content Types
      • Element Types
      • Compositions
    • Current Content Properties
      • Textbox & Textarea
      • Text Editor (Radzen)
      • Text Editor (TinyMCE)
      • Numeric
      • True / False
      • Rating
      • Checkbox, Dropdown & Radio Lists
      • Media Picker
      • Navigation
      • Material Icon Picker
      • Content Picker
      • Date Picker
      • Custom Component Picker
      • Api Key Picker
      • Colour Picker
      • Block List Editor
      • Editor Notes
      • Google Map Location Picker
      • Simple List Manager
      • Simple Dictionary Manager
      • SEO Property
      • Code Editor
      • Colour Theme Picker
    • Content
      • Publish & Unpublish
    • Querying Data
      • Extension Methods
    • Views
    • Controllers (Route Hi-Jacking)
    • Custom Components
    • Users & Roles
      • Restrict Access By Role
    • Logs
    • Audit
    • Global Settings
      • Using Global Settings
    • SEO Sitemaps
    • Hosting
  • Extending ZauberCMS
    • Overview
    • BlockListEditor
      • Content Block Preview
      • Content Block
    • Custom List Data
    • Custom Content Property
    • Custom Validation
    • Custom Admin Sections
      • Section Nav Group Menu
      • Trees
        • Tree Context Menus
      • Reusing Content Editors
    • Saving Custom Data
    • Using AppState Events
    • Before & After Save
    • Email & Storage Providers
    • Seed Data
    • SEO Checks
  • Identity
    • Overview
    • External Authentication Providers
    • Account Layout
  • Language
    • Overview
    • Adding Language Dictionaries
    • Setting The Language
    • Using Language Dictionaries
  • AppSettings
    • Detailed Errors
    • Media Settings
    • Enable Path Urls
Powered by GitBook
On this page
  • Content Views On A Content Type
  • Content Views Selection On Content
  • Views
  • ZauberViewPage<T>
  • Example
  1. Creating A Website

Views

PreviousExtension MethodsNextControllers (Route Hi-Jacking)

Last updated 3 months ago

Normal .Net Razor Views are used to display the content from your content types to the front end user of your website. A content type could have many content views, which in turn allows the user to select different Views (Think templates) to render their content. All Views must inherit from ZauberViewPage<T> to show in the Allowed Views selection on a content type (More about this below)

Content Views On A Content Type

Content Views Selection On Content

As you can see, on content, the user can only select a one View from whatever Content Views you have allowed them to choose from (See above)

Views

ZauberViewPage<T>

Any View that you want to use for your Content must inherit from ZauberViewPage<T>, where T by default would be 'Content' as Content is passed by default into the View.

@inherits ZauberCMS.Core.Rendering.ZauberViewPage<ZauberCMS.Core.Content.Models.Content>

Example

The below example is the Home View from the starter site

@using ZauberCMS.Core.Extensions
@inherits ZauberCMS.Core.Rendering.ZauberViewPage<ZauberCMS.Web.Home.Models.HomeViewModel>

<header class="masthead" style="background-image: url('@(Model.HeaderImage?.Url)')">
    <div class="container position-relative px-4 px-lg-5">
        <div class="row gx-4 gx-lg-5 justify-content-center">
            <div class="col-md-10 col-lg-8 col-xl-7">
                <div class="site-heading">
                    <h1>@(Model.GetValue<string>("Heading"))</h1>
                    <span class="subheading">@(Model.GetValue<string>("SubHeading"))</span>
                </div>
            </div>
        </div>
    </div>
</header>

<div class="container px-4 px-lg-5">

    <div class="row gx-4 gx-lg-5 justify-content-center">
        <div class="col-md-10 col-lg-8 col-xl-7">
            @Html.Raw(Model.GetValue<string>("Content") ?? string.Empty)
            <hr class="my-4"/>
            @foreach (var post in Model.BlogPosts)
            {
                @await Component.InvokeAsync("BlogPostPreview", new { post })
                <hr class="my-4"/>
            }
        </div>
    </div>
</div>

Just like a normal MVC project, all Views go into the Views folder in the root of your project. The folder convention works exactly like a normal MVC project. The only difference is by default, Content views are looked for in the root of the Views folder if you have not created a .

This will allow you to use @Model in the View and get data from the Content model (Or Model of your choice). If you want to use a custom model, then you need to add a

Controller (Route Hi-Jacking)
controller (Route Hi-Jacking).
Querying Data
Allowed Views On A Content Type
Content View Dropdown