0 votes


Sugar for RenderPage (and Html.Partial - see below)

- an efficient way of rendering razor templates
It picks up changes immediately and requires no app restarts

Demonstration http://www.screenr.com/4Sz7

Newest version (0.97 BETA - for Umbraco 4.7+ (not 6)), more convention based sugar:

Is it fast enough? It should be, it is built in RenderPage behaviour (and same as Partial in MVC): The razor pages are compiled on first use and kept in memory after that. Even if you have a complex template structure it should add minimum overhead.

@using RazorTemplates

 @{var tmpl = new Templates(Model);}

   // renders /macroscripts/{doctypealias}/header.cshtml (with model header)

  // fallbacks to
  // /macroscripts/shared/header.cshtml
  // /macroscripts/{doctypealias}/_default.cshtml
  // /macroscripts/shared/_default.cshtml

which migth simply look like:

PageData[0] is the "template view model"

@using RazorTemplates
@{ dynamic tmpl = new Templates(); }

It checks type name of the object - or NodeTypeAlias if that property exists and renders the .cshtml with that name sending someObject to PageData[0]
Default template location : /macroScripts (= the standard umbraco razor path)

Alternative usage:

The optional parameter(s) can be used in the .cshtml by the use of PageData[], for example:
@{var viewModel = (MyModelType)PageData[0];}

Also - RenderPage keeps the context, so you can use the existing Model

This means you can save templates for your Document types in Umbraco and render the correct template just by using @template.Render(myNode) renders /macroScripts/MyNodeTypeAlias.cshtml

If you like to render different templates at different times, just specify template folder to find the templates in
Templates("~/wherever") keeps the path as specified
Templates("/relativeToTemplateRoot") uses path relative to /macroScripts
Templates("relativeToCurrent") uses path relative to current path (i.e. subtemplates in same folder)
Templates() uses /macroScripts
Templates("") uses current path

Usage in MVC:

Version 0.90 is for Umbraco 6 and includes both rendering for WebPages (based on RenderPage) and MVC (based on Html.Partial). Usage in MVC:


@{var t = Html.Templates();}



Package owner

Jonas Eriksson

Jonas Eriksson

Jonas has 1825 karma points

Package Compatibility

This package is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud
Version 8.8.x (untested)
Version 8.7.x (untested)
Version 8.6.x (untested)
Version 8.5.x (untested)
Version 8.4.x (untested)
Version 8.3.x (untested)
Version 8.2.x (untested)
Version 8.1.x (untested)
Version 8.0.x (untested)
Version 7.15.x (untested)
Version 7.14.x (untested)
Version 7.13.x (untested)
Version 7.12.x (untested)
Version 7.11.x (untested)
Version 7.10.x (untested)
Version 7.9.x (untested)
Version 7.8.x (untested)
Version 7.7.x (untested)
Version 7.6.x (untested)
Version 7.5.x (untested)
Version 7.4.x (untested)
Version 7.3.x (untested)
Version 7.2.x (untested)
Version 7.1.x (untested)
Version 7.0.x (untested)
Version 6.2.x (untested)

You must login before you can report on package compatibility.

Package Information

  • Package owner: Jonas Eriksson
  • Created: 07/03/2013
  • Current version 0.96
  • License MIT
  • Downloads on Our: 1594