Table of Contents

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

C#, Razor & Dynamic Code

When you implement solutions using 2sxc, most of your server-side code will be written in C#.

C# Files in 2sxc Apps

You will create many dynamic .cs or .cshtml files in the App folder:

  1. Razor components and shared Razor views
  2. WebApi Controllers (*Controller.cs files in the api folder)
  3. Shared, pre-compiled App Code (*.cs files in each apps AppCode folder)
  4. Shared code (*.cs files in any folder)
Tip

These files are in your App folder as Dynamic Code and have three core features:

  1. The source code can be changed at any time
  2. Changes are immediately live without restarting the CMS
  3. Cool APIs 😎 help you work with dynamic data (Entities)

Quick Example

The variable person in the following Razor template is a special data object. It can have different properties depending on what it represents. In this case it has FirstName, LastName and Gender.

<div @Edit.Toolbar(person)>
  @person.FirstName @person.LastName - @Text.First(person.Gender, "unknown")
</div>

The code first creates a div tag which would show a hover-toolbar (to admins only) for editing the person. It then shows the names and the gender - which if not determined will show as unknown.

Note

This kind of code is easy understand for people who know HTML. It's also very easy to customize if you need a different output - since it's basically HTML and placeholders.

Important APIs

In general the API is split into 5 topics:

  1. Data API to get and show data
  2. Context API to get information about the current user, page, etc.
  3. Settings APIs to get configuration information
  4. Edit APIs to show edit toolbars and other edit features
  5. Extensive other APIs usually on the Kit object to do all kinds of things like JSON parsing, file handling, etc.

What's Where

This documentation contains the following sections

  1. Dynamic Data Everything you need to understand how data, especially dynamic data, works in 2sxc.
  2. Dynamic Code The shared API on all Dynamic Code - Razor, WebApi or other.
  3. Razor The APIs special to Razor templates
  4. Web API Everything you need to know to create/customize Web API Controllers
  5. External API Guides you to access 2sxc-instances on the server from the Theme, WebForms or other MVC components

Important APIs when Working with Content-Items/Data

TODO: this must be moved elsewhere

  1. DataSource and DataStream, the core concept for data read/processing/delivery
    1. List of all DataSource Objects
    2. how to create custom data sources