Namespace ToSic.Razor.Blade
This is the main namespace you will be working with. Add it to your page like this:
@using ToSic.Razor.Blade;
After that you can simply use the commands - so here's a super simple cshtml file:
@using ToSic.Razor.Blade;
<div>
@Text.Ellipsis("this text is much too long & will need to be truncated", 25)
</div>
Classes
Tag
Helper to quickly generate all HTML5 tags with a Tag.Img() or Tag.Table() syntax.
This is the easiest and safest way to use in in Razor templates because you won't have naming issues etc.
The objects are smart - for example this will automatically uri-encode 😎
Tag.Img().Src("ünsafe.jpg")
Important: Tag can easily be confused with the Tags object.
new in 3.0
Tags
The Tags-API is for manipulating strings which contain html or should contain html
- like stripping away tags, converting
<br>
tags to new-lines and similar.
Important: Tags can easily be confused with the Tag object.
Text
Many simple commands to work with Text / Strings
Interfaces
IHtmlTag
Public interface for all Html5Tags
IHtmlTagsService
The service to generate HTML Tags.
Tip
This is the new, recommended way of generating tags, as it's better and functional
Warning
This looks almost the same as the static ToSic.Razor.Blade.Tag
but there is a crucial difference
The APIs return functional IHtmlTag
objects.
This is safer and more future proof, but you may run into surprises.
Example:
// Old Tag API - these two objects will be the same
var tagOld = ToSic.Razor.Blade.Tag.Div();
var tagOldWithId = tagOld.Id(...).Style(...).Class(...);
// now tagOld and tagOldWithId are both the same objects with all changes applied
// New API - assumes tagSvc is IHtmlTagsService
// these two objects will NOT be the same
var tag = tagSvc.Div();
var tagWithId = tag.Id(...).Style(...).Class(...);
// now tag is still an empty div-tag
// while tagWithId is the tag wth everything set on
IScrub
IScrub helps wash/clean html from things you want removed. It can take care of all tags, just specific tags or certain attributes.
Note that it is implemented as an interface, so you must use Dependency Injection to get it.