API Docs of RazorBlade 4.00
These docs are meant for programmers using RazorBlade. These will usually be people working with C# and Razor, MVC etc.
APIs you're probably looking for
- APIs for Text with commands like
Crop(...)
,Ellipsis(...)
,First(...)
,Has(...)
,Zip(...)
- API for Tags with commands like
- Text to HTML conversions:
Br2Nl(...)
,Br2Space(...)
,Decode(...)
,Encode(...)
,Nl2Br(...)
, ... - Html generators:
Attribute(...)
,Attributes(...)
,Tag(...)
- Text to HTML conversions:
- API for Tag with all known html5 tags like
A(...)
,Abbr(...)
,Address(...)
,Area(...)
all the way toWbr(...)
- API for HtmlPage with
- Page properties (get/set):
Description
,Keywords
,Title
, ... - Methods to add headers:
AddIcon(...)
,AddIconSet(...)
,AddJsonLd(...)
,AddMeta(...)
, ...
- Page properties (get/set):
Tutorials & Blogs
- An explanation of the Fluent Tag API
- We have an extensive tutorial on 2sxc for using RazorBlade
- We also have many blog posts on RazorBlade
What is RazorBlade 3?
A library of common functions for Razor, to lighten Razor templates and make work easier. Some examples:
You need to change the page title and some headers from a razor template:
@using ToSic.Razor.Blade;
HtmlPage.Title = "Title changed using Razor Blade! original";
HtmlPage.Description = "Learn to use Razor Blade " + HtmlPage.Description;
HtmlPage.Keywords = "Tutorial, Razor, Blade" + HtmlPage.Keywords;
HtmlPage.AddMeta("somename", "somevalue");
HtmlPage.AddIcon("iconfile.png");
You need the first 100 characters followed by an ellipsis (if truncated), but umlauts like ü
will mess up your count or might even be cut off. This is automatically handled by:
@* just cut it off at the visible character count, not splitting words *@
@Text.Crop(someText, 100)
@* truncate a text and if necessary, add ellipsis character *@
@Text.Ellipsis(longText, 100)
@* now the same thing, with text having html-tags *@
@Text.Ellipsis(Tags.Strip(longText), 100)
You need a value, but if it's empty (null, spaces, line-breaks,
etc.), you need another one:
@* Do this *@
@Text.First(firstName, "nothing found");
@* instead of this *@
@if(String.IsNullOrWhiteSpace(firstName as string)) {
@"nothing found"
} else {
@firstName
}
Note that HTML whitespace like
will also be treated as empty, unless you add false
as a last parameter. But RazorBlade does more than just skip empty texts, here some more examples:
@* First non-empty of many possible values *@
@Text.First(nameFromDb, nameFromProfile, defaultNameForThisCountry, "unknown")
@* remove html from a wysiwyg-string *@
@Tags.Strip(formattedText)
@* the same with a custom ending *@
@Text.Ellipsis(longText, 100, "...more")
@* an it won't cut off in the middle of ä *@
@Text.Ellipsis("Visit München", 10)
Nice to Know
- RazorBlade has 340 unit tests to make it rock-solid!
- The last update was December 2022 when we released v4.00
- See the Change Log