#1 Safe Html5 Attributes from code
RazorBlade Safe Attributes API @Tag.Attr v3
Here we'll go through some examples using @Tag.Attr(...)
Creating Simple Attributes
This is a simple demo showing how to add the title
and class
attribute using code.
It switches between warning/primary depending of the second being odd or even. Refresh the page to see the difference.
If you mouse-over, you'll also see the tooltips showing stuff which would cause trouble otherwise.
<div @Tag.Attr("title", titleWithIssues)
@Tag.Attr("class", cls)
@Tag.Attr("number", 27)>
This is a simple demo showing how to add... <!-- unimportant stuff, hidden -->
</div>
#1 Safe Html5 Attributes from code
@inherits Custom.Hybrid.Razor14
@using ToSic.Razor.Blade;
<!-- unimportant stuff, hidden -->
RazorBlade Safe Attributes API... <!-- unimportant stuff, hidden -->
Creating Simple Attributes
@{
var titleWithIssues = "I said \"check this out!\" \n\n even 'different quotes' and line breaks work!";
var cls = "alert alert-";
cls += (DateTime.Now.Second % 2 == 0) ? "warning" : "primary";
}
<div @Tag.Attr("title", titleWithIssues)
@Tag.Attr("class", cls)
@Tag.Attr("number", 27)>
This is a simple demo showing how to add... <!-- unimportant stuff, hidden -->
</div>
<!-- unimportant stuff, hidden -->