Skip to main content

Razor Blade Tutorials

Tutorial HomeRazor.Blade

Learn how to use ToSic.Razor.Blade to do really cool stuff. For example, take a html-string, strip the html tags, truncate to 100 characters without splitting word and then show using a standard html-ellipsis. And way more. This uses ToSic.Razor.Blade.

Some notes before we start

RazorBlade can be installed as a stand-alone DNN module or if you are creating your own module, you can include it in your distribution. 2sxc 9.40+ includes RazorBlade 1.01, 2sxc 10.06 includes 2.0 and 10.09 includes v2.02. If you see errors, you probably need to install a newer version of RazorBlade.


RazorBlade Examples for Text Manipulations

  1. RazorBlade - Text.Crop() and Text.Ellipsis() v1.00
    Correctly crop text without splitting words or html-characters like &
  2. RazorBlade - Text.Has() tells you if something really has content v1.00
    Check if strings really have something correctly, incl. spaces or even   whitespaces.
  3. RazorBlade - Text.First() lets you pick a value from many variables v3.00
    Often you have to check many variables to find the first one to use.
  4. RazorBlade - Text.Zip() lets you shrink all spaces, tabs, enters together v1.00
    Very often you need to clean up some text before working with it.

RazorBlade Examples for Manipulating Html strings

  1. Tags.Strip() cleans out all HTML tags v1.00
    Remove all html from a string - important for teaser texts and protecting against cross-site-scripting attacks.
  2. Convert <br> tags to new-lines or spaces and back v1.00
    A common challenge is showing text as HTML or the other way around

RazorBlade Examples for Modifying DNN Page Headers

  1. Page Title, Keyword, Description v1.01
    Get/Set Page Title, Keywords, Description and set meta-tags and more.
  2. Base tag in header (new!) v3.00
    Add a base tag to the header - which works correctly in DNN. Important for SPA JS applications.
  3. JSON-LD Headers for SEO v1.01
    Add JSON-LD (Linked Data) headers for Google
  4. Open-Graph headers for Social Media v1.01
    Add Open-Graph data headers for Facebook, Twitter and other sharing-systems
  5. Open-Graph headers for Social Media v1.01
    Add Open-Graph data headers for Facebook, Twitter and other sharing-systems
  6. Page Icons for Favicon, Apple/Android new! v2.01
    Add various combinations of icons to the page header

RazorBlade Fluent Html and Html5 Tag API for creating HTML using code

  1. Tutorials for the Html5 Tag API enhanced! v3.00
    The basics of creating html directly from code - with objects for every known HTML5 tag

More Information around RazorBlade

  1. RazorBlade Github Repo
  2. RazorBlade download page
  3. Blogs