我希望根据文档的内容显示一个自定义标题,而不是定义单个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语句和一个调试器断点检查了这一点。
有没有什么是我可能遗漏的,或者是另一种显示自定义文档标题的方式?
发布于 2021-01-29 21:28:51
覆盖我的presenter类中的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
endhttps://stackoverflow.com/questions/65953879
复制相似问题