Razor Tutorial - Home (11.2.1)
How to use this Tutorial
Below you'll find a list of topics this tutorial covers. The easiest way to work with it is to look at an example, then look at the code shown below the examples. You can also modify the source files and see what happens :)
Basic use of Razor with variables, loops, conditions etc.
Working with HTML
Learn the difference of showing variables with
@Html.Raw(variable), and re-using snippets with
Using Emojis / Emoticons 👍
Show Emojis in your output or use them for showing true/false
Reuse templates and code
enhanced for v11
You can place common templates, hlp and functions into shared files - both
.cs. And you can split Razor files into code and templates.
Working with Content & Data
In most cases a template will run in a context - so something prepared data for the template, which should now be visualized. These examples assume you're working with 2sxc, which lets editors work with content - and your template only needs to visualize it.
Working with Entity (Item) Values
new in 10.27
Every thing is an Entity. Here some basic examples how to show values like Name, Birthday etc. of such an Entity.
Visualize current Content
enhanced in 10.27
Show content which was entered for this module
Show data from DNN, the current App, DataSources or SQL, CSV etc. Also includes list/details (parent/child) examples.
Easily work with JSON data.
The following examples show how to use LINQ (Language INtegrated Query) to sort, filter and group data. This is for quick work in your views - for more extensive querying, we recommend the Visual Query Designer.
Customize Edit UI / UX
Sometimes you want to customize what the editor will experience - using special toolbars or custom input fields. Note that this only applies to 2sxc.
Customize the Edit Experience
new in v11
Customize the editor experience by providing great toolbars or custom input fields
These examples help you quickly do hard stuff, once you've mastered the basics above
RazorBlade - Making real tasks easier
Properly create preview-texts, strip HTML, pick the right variables, set page titles and way more. Includes...
RazorBlade - using the Html5 Tag API
- Text manipulation, clean-up, cropping and ellipsis
- Picking the ideal string-values
- Html stripping for teasers and to protect against XSS
- Convert html to text and back
- Set page title, headers, keywords
- Create SEO JSON-LD headers
- Create social media Open-Graph headers
- Create favicons, apple-icons, android icons and more (new!)
- Add base-tags with the correct url (new!)
The basics of creating html directly from code - new in 2.0 and enhanced in 2.1
These examples help you do cool stuff, once you've mastered the basics above
Koi - Cool things with CSS-Frameworks and Classes
Automatically include missing frameworks, conditionally modify the HTML or CSS-Classes and more, depending on what CSS-framework is used by the theme of this page.
Provide data to SPAs and do things like sending mails, changing data and more.
Crazy 2sxc Advanced Examples
These are really advanced examples and meant more to give guidance for specific questions. Don't worry if you don't understand these
2sxc Advanced Stuff
Really special crazy stuff
Next Tutorials (Work-In-Progress
We'll create some more tutorials in March/April 2019, incl. the following
- Linking around in dnn
- Using js/css and image resources in the app folder
- Using app settings and resources
- Image Resizing on the server
- Navigation links
- Leveraging Connect.Koi
- Permission examples
- In-Page Editing experience
- Customizing Search Results
- Add multi-language examples
- work with icon-fonts, font-awesome etc.
- More data examples, working with users, SQL-write, PetaPoco etc.
- Working with DataSources in all kinds of ways
- Using data from other apps
- customizing search from data
- custom dynamic WebApi