Templates
Templates
Templates allow you to define some content to show inside another razor file. This makes it easy to make components more agile and reusable.
Here's a simple example, here's InfoCard.razor
Then you can use this in other components like this
As you can see, we're defining the insides of the InfoCard panel. We can even add events and functions that add interactions from the parent panel.
With Arguments
RenderFragment<T> is used to define a fragment that takes an argument.
Here's how it works, here's EntityList.razor
As you can see we're now defining EntityRow
that takes an argument. To call it we just call it like a function, with the entity argument.
Now to use EntityList
we do this
In the EntityRow we add the special attribute Context
, which tells our code generator that this is going to need a special object context
.
Then in the fragment, we can convert this object
into our target type. Then you're free to use it as you wish.
Elements inside components
All panels have a render fragment called ChildContent, so you can add elements inside of any component without adding your own.