Jozef Mares
Jozef Mares

Reputation: 31

Django-cms haystack search - placeholder content

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.

Upvotes: 0

Views: 964

Answers (1)

Jozef Mares
Jozef Mares

Reputation: 31

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.

Upvotes: 3

Related Questions