Skip to main content

Reuse Templates and Code Tutorials

Tutorial Home

Reuse templates and code

This will show you how to place partial templates into separate files, and how to put functions you need in many places in separate files as well. It focuses on:

  1. @Html.Partial(...) to render another page (older versions of 2sxc used @RenderPage(...)) - see docs
  2. DynamicModel is the object used in sub-pages to receive parameters from the caller - see docs
  3. CreateInstance(...) to create objects from .cs files - see docs
  4. Func<dynamic, dynamic> micro-helpers are ideal for small sub-templates - see docs
Requirements

Reuse Shared Stuff Examples

  1. Micro-Helpers (like functions) with Template Delegates
  2. Reuse Razor Components with @Html.Partial and DynamicModel
  3. Reuse Razor Helpers (mini-templates) with CreateInstance
  4. Reuse a function library CreateInstance
  5. Reuse code with .cs files
    CreateInstance is enhanced in 2sxc 10.01 to support .cs files to share code across Razor files and WebApi Controllers.

Deprecated Features

This shows / documents features which work, but are not recommended any more:

  1. Split Razor Templates into C#-Code and Template deprecated, Dnn Only
    Now you can split out complicated C# code so designers don't have to worry about it.