Template Delegates allow you to use inline HTML in your function. To make this possible, a bit of magic happens automatically, so a limitations is that you cannot use named parameters. You only get one parameter called item
.
Basic Example: string
generating Html
This example using a string
parameter. This is why the the first parameter in Func<...
is a string.
Note that in the following code item
is the thing passed into the function.
⬇️ Result | Source ➡️
-
this is text, it doesn't have tags
-
this string has html tags
-
this is just a bold line
@inherits Custom.Hybrid.RazorTyped
@{
var normalText = "this is text, it doesn't have tags";
var htmlText = "this string <em>has</em> html <strong>tags</strong>";
// Simple Hybrid (Dnn/Oqtane) Template Delegate
Func<string, dynamic> BoldLi = @<li>
<strong>
@Html.Raw(item)
</strong>
</li>;
}
<ul>
@BoldLi(normalText)
@BoldLi(htmlText)
@BoldLi("this is just a bold line")
</ul>