0
我使用的是cmsplugin-blog與Django-cms。我想在主頁上顯示最新的博客條目列表(未與插件掛鉤)。爲此,我創建了一個模板標籤。我可以得到一組條目,但不知道如何呈現其標題。任何人都可以指向正確的方向嗎?模板標籤在主頁上發佈cmsplugin博客條目的列表
這是代碼。
cmsplugin_blog_tags.py:
17 # blog post widget
18 @register.inclusion_tag('cmsplugin_blog/entry_list_1_snippet.html', takes_context=True)
19 def render_entries_widget(context, entry_num):
20 request = context["request"]
21 language = get_language_from_request(request)
22 kw = get_translation_filter_language(Entry, language)
23
24 return {
25 'entries': Entry.published.filter(**kw)[0:entry_num],
26 }
entry_list_1_snippet.html:
1 {% load i18n placeholder_tags cmsplugin_blog_tags simple_translation_tags %}
2
...
3 <div id="featposts-widget-2" class="widget featposts">
4 <div class="widget-wrap">
5 <h3 class="widgettitle"><span><a href="/blog">{% trans "VFOSS Blog" %}</a></span></h3>
6 <div class="cat-posts-widget textwidget">
7
8 {% for entry in entries|annotate_with_translations %}
# line 9 does not work. Probably no request.
9 {% with entry|get_preferred_translation_from_request:request as title %}
# no excerpt showed.
10 {% with entry.placeholders|choose_placeholder:"blog_excerpt" as excerpt %}
11