我将 cmsplugin-blog 与 Django-cms 一起使用。我想在主页中显示最新博客条目的列表(不与插件挂钩)。为此,我创建了一个模板标签。我可以获得一组条目,但不知道如何呈现它们的标题。谁能指出我正确的方向?
这是代码。
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