繁体   English   中英

如何在 Blacklight 中为文档标题添加自定义逻辑?

[英]How can I add custom logic for the title of a document in Blacklight?

我不想定义单个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

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

有没有我可能错过的东西或其他显示自定义文档标题的方法?

在我的演示者 class 中覆盖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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM