Skip to content

Field Value Rendering Pipeline

Cory Lown edited this page Feb 22, 2024 · 1 revision

How it works?

Blacklight provides a pipeline of operations that are performed on each field value. This is defined in the Blacklight::Rendering::Pipeline class.

By default this class defines a list of operations to perform on each field (each possibly with multiple values):

self.operations = [HelperMethod, LinkToFacet, Microdata, Join]

The HelperMethod executes the helper method (if it is defined in the field configuration) and then terminates the pipeline.

The LinkToFacet turns the value into a link to the facet with that value.

The Microdata decorates the value with Schema.org microdata.

The Join takes the list of values and concatenates them with to_sentence

Customizing

Let's say we want to swap out the built in Join method with our own version. First create config/initializers/blacklight.rb that has all the default values, except with our custom class.

Blacklight::Rendering::Pipeline.operations = [Blacklight::Rendering::HelperMethod,
                                              Blacklight::Rendering::LinkToFacet,
                                              Blacklight::Rendering::Microdata,
                                              CustomJoin]

Then make the CustomJoin class in app/processors/custom_join.rb

# Joins values using configured value or linebreak
class CustomJoin < Blacklight::Rendering::AbstractStep
  include ActionView::Helpers::TextHelper

  def render
    joiner = config.join_with || '<br>'.html_safe
    next_step(safe_join(values, joiner))
  end
end
Clone this wiki locally