razor and the art of templating

20
Razor and the Art of Templating Jess Chadwick Team Lead / Architect / RIA Specialist blog.jesschadwick.com @jchadwick [email protected]

Upload: jess-chadwick

Post on 18-Dec-2014

3.245 views

Category:

Technology


1 download

DESCRIPTION

Though I deliberately went easy on the slides and heavy on the code, there might be a few nuggets in here so I'm posting it anyway. Enjoy!

TRANSCRIPT

Page 1: Razor and the Art of Templating

Razor and the Art of Templating

Jess ChadwickTeam Lead / Architect / RIA Specialist

blog.jesschadwick.com@jchadwick

[email protected]

Page 2: Razor and the Art of Templating

Razor basicsRazor & ASP.NET MVCExtending Razor

Agenda

Page 3: Razor and the Art of Templating

What is Razor?

Page 4: Razor and the Art of Templating

What is Razor?

Page 5: Razor and the Art of Templating

A New View

View

Controller

Model

Page 6: Razor and the Art of Templating

Simplicity &

Elegance

Code & Markup

Page 7: Razor and the Art of Templating

DEMOASPX vs. Razor

Page 8: Razor and the Art of Templating

Creating Views

Page 9: Razor and the Art of Templating

1. Combine code and markup Don’t think about it

2. @ indicates a code block

3. Standard language keywordse.g. foreach, using, inherits, etc.

Basic Syntax: 3 Simple Rules

Page 10: Razor and the Art of Templating

Create a main site layout(think “Master Page”)

Implement content of each page in sections Think ContentPlaceHolder RenderBody() RenderSection()

Designing a Site Layout

Page 11: Razor and the Art of Templating

functions keyword defines a code section(think <script runat=“server”>)

helper keyword defines a reusable Razor section

Functions and Helpers

Page 12: Razor and the Art of Templating

Razor and ASP.NET MVCLike peanut butter and chocolate

Page 13: Razor and the Art of Templating

model

New Keyword:

Page 14: Razor and the Art of Templating

Pause… Time out.It’s gonna get scary.

Page 15: Razor and the Art of Templating

The Razor APIDiving deeper…

Page 16: Razor and the Art of Templating

Engine

The Razor API

Parser Generator

Host

Page 17: Razor and the Art of Templating

Code + Markup

Parsed Document

Code Compile

Unit.NET Class

Lifecycle of a Razor Template

Page 18: Razor and the Art of Templating

Questions / Comments?

Page 20: Razor and the Art of Templating

The Razor View

Lifecycle