【问题标题】:Django-cms haystack search - placeholder contentDjango-cms haystack 搜索 - 占位符内容
【发布时间】:2012-04-21 19:47:52
【问题描述】:

我对 django-cms 和 haystack 搜索的结果有疑问。我正在使用 django-cms-search 插件,haystack 作为后端。 Haystack 返回正确的结果。但我想在搜索结果中显示“预告片”。

我可以通过这种方式通过模板访问绝对 URL 和页面标题:

{% for result in page.object_list %}
<div class="searchResults">
<h2>{{ result.object.get_title }}</h2>
{{ result.object.placeholders.all }}           
<p><a href="{{ result.object.get_absolute_url }}">{% blocktrans %} Read more {% endblocktrans %}</a></p>

有问题的部分是{{ result.object.placeholders.all }}。我在每个页面内容的占位符中都有名称内容。

{{ result.object.placeholders.all }} 仅返回占位符的名称。

搜索结果应如下所示:

页面标题

页面预告

阅读更多链接

在预告片中应该有来自搜索匹配页面的前 50 个单词。

这是否可以从模板访问占位符内容?

感谢您的提示。

【问题讨论】:

    标签: python django templates django-haystack django-cms


    【解决方案1】:

    Haystack 有模板标签 higlight,可以按照我的要求创建“预告片”。

    模板代码如下所示:

    {{ result.object.get_title }}
    {% highlight result.text with request.GET.q max_lenght 40 %}
    {{ result.object.get_absolute_url }}
    

    感谢#haystack IRC 频道的各位。

    【讨论】:

      猜你喜欢
      • 2013-09-07
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 2011-07-22
      • 2014-08-31
      • 2017-12-24
      • 2013-10-08
      • 2012-11-02
      相关资源
      最近更新 更多