1

title_field我不想定义一个单独的标题,而是根据文档的内容显示一个自定义标题。根据Blacklight Wiki,这可以通过设置config.index.document_presenter_class自定义演示者来完成:

# app/controllers/catalog_controller.rb
class CatalogController < ApplicationController
  ...
  configure_blacklight do |config|
    ...
    config.index.document_presenter_class = MyPresenter
    ...
  end
  ...
end

自定义演示者覆盖label方法的地方:

# app/presenters/my_presenter.rb
class MyPresenter < Blacklight::IndexPresenter
  def label(field_or_string_or_proc, opts = {})
    # Assuming that :main_title and :sub_title are field names on the Solr document.
    document.first(:main_title) + " - " + document.first(:sub_title)
  end
end

当我这样做时,我的自定义标签方法似乎没有被调用,我通过添加一条puts语句和一个调试器断点来检查它。

是否有我可能错过的内容或显示自定义文档标题的其他方式?

4

1 回答 1

1

在我的演示者类中覆盖该heading方法对我有用:

# app/presenters/my_presenter.rb
class MyPresenter < Blacklight::IndexPresenter
  def heading
    # Assuming that :main_title and :sub_title are field names on the Solr document.
    document.first(:main_title) + " - " + document.first(:sub_title)
  end
end
于 2021-01-29T13:28:50.543 回答