Table of Contents

RazorBlade Library

2sxc includes RazorBlade - a very neat library of helper tools to get things done. It includes features such as:

  1. Text helpers to check if something has text, truncate/ellipsis text and more
  2. Tags helpers to strip HTML, make safe URLs and more
  3. Tag fluent API to create complex HTML using code
  4. HtmlPage helper to change the page title, add meta- and open-graph headers etc.

Discover More in the RazorBlade Tutorials

We have an rich series of RazorBlade tutorials. You should really check them out 👍.


The following example is taken from the tutorials. It shows how to use @Text.Zip(...) to ensure that a string containing random white spaces is cleaned up. This is useful for counting visible characters or truncating text.

@inherits Custom.Hybrid.Razor12
@using ToSic.Razor.Blade;
  var samples = new string[] {
    "This        contains multi-spaces and \t\t\t tabs",
    "This has \n  \n line-breaks"

<h2>Correct and incorrect Character Counts</h2>

<table class="table table-hover" width="100%">
    <!-- table header -->
        <th>Html output hides the problems</th>
        <th class="table-warning">Whitespace output showing problems</th>
        <th class="table-success">Output using Text.Zip(...)</th>
        <th>Zip Length</th>
    <!-- the real code -->
    @foreach(var s in samples) {
        <td>@s </td>
        <td  class="table-warning" style="white-space: pre-wrap;">@s</td>
        <td>@s.Length </td>
        <td class="table-success" style="white-space: pre-wrap;">@Text.Zip(s)</td>

Learn to Leverage RazorBlade