Fork me on GitHub
2sxc 9.4 for DNN 7 to 9
Website Builder, Content Manager, App-System: open-source and amazing
You are here: Home  >  Learn  >  Razor Templates and Views

Learn Razor for Advanced, Funky Stuff

Razor is a standard Microsoft technology for templating HTML. Because of this, there i a LOT of information out in the web related to Razor that you can use. To use Razor with 2sxc, you should:

  1. Learn the basics of Razor - using simple 2sxc samples and examples / tutorials from around the web
  2. Learn what 2sxc adds to Razor - to leverage that as well
  3. Learn the best ways to solve common issues (not documented yet, todo)
  4. Learn related technologies like LINQ to build on that (not documented yet, todo)

Step 1: Learn Razor Basics

You want to understand the very basics of Razor. To do this, I recommend you start with

  1. The two tutorial videos you'll see below
  2. Some external learning materials for more infos - linked after the videos
  3. Various Apps containing lots of code examples - also linked after the videos

First Steps with Razor

As easy as tokens and much more powerfull. You really want to get into Razor :)
See results here.

First Steps with Razor

Get to know Razor. FAQ-Demo here. Get App or look at results Razor here.

Having trouble getting Razor to work? Here's a list of typical technical issues.

Razor Lists

Using Razor to render lists is almost as easy as with Tokens, but opens a universe of possibilities.
See results here.

Razor Lists

Using Razor to render lists is almost as easy as with Tokens, but opens a universe of possibilities. The demo-code is here.

Step 2: Learn What 2sxc/DNN adds to Razor

I'm not done writing about this yet, but I'll try to just give you a quick summary:

  1. 2sxc usually takes care of getting Content or Data for your Template or View. So in general, you do not have to write any code to get content/data, it's just there. So there are at least x ways to get Content/Data
    1. In the basic data-objects like @Content or @ListContent - you'll see many code-samples using this
    2. From the @Data object which contains lists of content-items which were delivered to this template (MVC-Style). So Data["Default"] contains the main Stream of data, but together with the Visual-Query-Designer you can have many more streams. This is the preferred method for most data-lists and also works for SQL, CSV, FnL data etc. 
    3. The @App.Data object is the global data-object for this App, giving you code-access to all Content-Items in this App
    4. Using custom C# code to get data in the Intialize-section of your template - like for SQL or other data.
  2. 2sxc gives you access to DNN material using the @Dnn Variable. It's identical to the standard Dnn Variable
  3. 2sxc also provides additional helpers like AsDynamic, AsEntity and more. You'll see many such examples in the demo-apps and code samples. 

 

I'll try to write more about all this later on, but I think you'll find most of it intuitive if you check out some example Apps.

Relationships - Connecting Information

Here's how you can connect information - like articles and tags or courses and authors.
See results here.

Relationships - Connecting Information

Here's how you can connect information - like articles and tags or courses and authors. Code here.
2serve . 2invent . 2create is 2be.