Skip to content

Tag Helper Renderers

Jamie Pollock edited this page Jan 11, 2024 · 3 revisions

Tag Helper Renderers are a way for developers to modify how a drop tag helper is rendered. A default tag helper renderer will always be provided by Rhythm Drop but in certain cases a developer may need to modify how things are rendered which are beyond the scope of what this library has to offer.

Adding your own

Each tag helper renderer can be overridden at startup within the AddRhythmDrop builder call.

builder.AddRhythmDrop((dropBuilder) => {
  /*
   * boilerplate dependencies (only needs to be called the first time AddRhythmDrop(configure) is called).
   * if AddRhythmDrop() was previously called this will not be needed.
   */
  dropBuilder.AddInfrastructure();
  dropBuilder.AddWeb();

  dropBuilder.SetDropImageTagHelperRenderer<MyCustomDropImageTagHelperRenderer>();
});

A tag helper will have a method that looks a bit like this:

Task RenderAsync(TModel? model, TagHelperContext context, TagHelperOutput output);

Where TModel? is the modified context provided to the code. This should contain all the information needed to modify the TagHelperOutput. The TagHelperContext is also present in case this contains information set by other logic or tag helpers which could be used by this code.

Clone this wiki locally