Django-cms haystack search - placeholder content

不想你离开。 提交于 2019-12-11 16:39:18

问题


i have problem with results in django-cms and haystack search. I'm using django-cms-search plugin, haystack as backend. Haystack returns correct results. But i want to show "teaser" in search results.

I can access absolute URL and title of page via template this way:

{% 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>

Problematic part is {{ result.object.placeholders.all }}. I have on every page content in placeholder with name content.

{{ result.object.placeholders.all }} returns only name of the placeholders.

Search results should look like this:

PAGE TITLE

PAGE TEASER

READ MORE LINK

In teaser there should be first 50 words from search-matched page.

Is this possible to access placeholder content from template?

Thank you for your tips.


回答1:


Haystack has templatetag higlight which creates "teaser" as i requested.

Template code can look like this:

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

Thanks to guys from #haystack IRC channel.



来源:https://stackoverflow.com/questions/10073189/django-cms-haystack-search-placeholder-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!